Search in sources :

Example 51 with LinearLayoutManager

use of android.support.v7.widget.LinearLayoutManager in project Fragmentation by YoKeyword.

the class FirstHomeFragment method initView.

private void initView(View view) {
    mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
    mRecy = (RecyclerView) view.findViewById(R.id.recy);
    mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
    mFab = (FloatingActionButton) view.findViewById(R.id.fab);
    mToolbar.setTitle("首页");
    mRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
    mRefreshLayout.setOnRefreshListener(this);
    mAdapter = new FirstHomeAdapter(_mActivity);
    LinearLayoutManager manager = new LinearLayoutManager(_mActivity);
    mRecy.setLayoutManager(manager);
    mRecy.setAdapter(mAdapter);
    mAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position, View view, RecyclerView.ViewHolder vh) {
            FirstDetailFragment fragment = FirstDetailFragment.newInstance(mAdapter.getItem(position));
            // LOLLIPOP(5.0)系统的 SharedElement支持有 系统BUG, 这里判断大于 > LOLLIPOP
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
                setExitTransition(new Fade());
                fragment.setEnterTransition(new Fade());
                fragment.setSharedElementReturnTransition(new DetailTransition());
                fragment.setSharedElementEnterTransition(new DetailTransition());
                // 25.1.0以下的support包,Material过渡动画只有在进栈时有,返回时没有;
                // 25.1.0+的support包,SharedElement正常
                fragment.transaction().addSharedElement(((FirstHomeAdapter.VH) vh).img, getString(R.string.image_transition)).addSharedElement(((FirstHomeAdapter.VH) vh).tvTitle, "tv").commit();
            }
            start(fragment);
        }
    });
    // Init Datas
    List<Article> articleList = new ArrayList<>();
    for (int i = 0; i < 15; i++) {
        int index = i % 5;
        Article article = new Article(mTitles[index], mImgRes[index]);
        articleList.add(article);
    }
    mAdapter.setDatas(articleList);
    mRecy.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            mScrollTotal += dy;
            if (mScrollTotal <= 0) {
                mInAtTop = true;
            } else {
                mInAtTop = false;
            }
            if (dy > 5) {
                mFab.hide();
            } else if (dy < -5) {
                mFab.show();
            }
        }
    });
    mFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(_mActivity, "Action", Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : OnItemClickListener(me.yokeyword.sample.demo_zhihu.listener.OnItemClickListener) Article(me.yokeyword.sample.demo_zhihu.entity.Article) ArrayList(java.util.ArrayList) FirstHomeAdapter(me.yokeyword.sample.demo_zhihu.adapter.FirstHomeAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) DetailTransition(me.yokeyword.sample.demo_zhihu.helper.DetailTransition) Fade(android.transition.Fade)

Example 52 with LinearLayoutManager

use of android.support.v7.widget.LinearLayoutManager in project Fragmentation by YoKeyword.

the class FirstPagerFragment method initView.

private void initView(View view) {
    EventBus.getDefault().register(this);
    mRecy = (RecyclerView) view.findViewById(R.id.recy);
    mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
    mRefreshLayout.setOnRefreshListener(this);
    mAdapter = new PagerAdapter(_mActivity);
    mRecy.setHasFixedSize(true);
    LinearLayoutManager manager = new LinearLayoutManager(_mActivity);
    mRecy.setLayoutManager(manager);
    mRecy.setAdapter(mAdapter);
    mRecy.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            mScrollTotal += dy;
            if (mScrollTotal <= 0) {
                mInAtTop = true;
            } else {
                mInAtTop = false;
            }
        }
    });
    mAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position, View view, RecyclerView.ViewHolder holder) {
            // 通知MainActivity跳转至CycleFragment
            EventBus.getDefault().post(new StartBrotherEvent(CycleFragment.newInstance(1)));
        }
    });
    // Init Datas
    List<String> items = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        String item = "联系人 " + i;
        items.add(item);
    }
    mAdapter.setDatas(items);
}
Also used : OnItemClickListener(me.yokeyword.sample.demo_wechat.listener.OnItemClickListener) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) PagerAdapter(me.yokeyword.sample.demo_wechat.adapter.PagerAdapter) StartBrotherEvent(me.yokeyword.sample.demo_wechat.event.StartBrotherEvent) RecyclerView(android.support.v7.widget.RecyclerView)

Example 53 with LinearLayoutManager

use of android.support.v7.widget.LinearLayoutManager in project Fragmentation by YoKeyword.

the class FirstPagerFragment method initView.

private void initView(View view) {
    mRecy = (RecyclerView) view.findViewById(R.id.recy);
    mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
    mRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
    mRefreshLayout.setOnRefreshListener(this);
    mAdapter = new HomeAdapter(_mActivity);
    LinearLayoutManager manager = new LinearLayoutManager(_mActivity);
    mRecy.setLayoutManager(manager);
    mRecy.setAdapter(mAdapter);
    mAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position, View view, RecyclerView.ViewHolder vh) {
            // 这里的DetailFragment在flow包里
            // 这里是父Fragment启动,要注意 栈层级
            ((SupportFragment) getParentFragment()).start(DetailFragment.newInstance(mAdapter.getItem(position).getTitle()));
        }
    });
    // Init Datas
    List<Article> articleList = new ArrayList<>();
    for (int i = 0; i < 15; i++) {
        int index = (int) (Math.random() * 3);
        Article article = new Article(mTitles[index], mContents[index]);
        articleList.add(article);
    }
    mAdapter.setDatas(articleList);
    mRecy.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            mScrollTotal += dy;
            if (mScrollTotal <= 0) {
                mAtTop = true;
            } else {
                mAtTop = false;
            }
        }
    });
}
Also used : OnItemClickListener(me.yokeyword.sample.demo_zhihu.listener.OnItemClickListener) Article(me.yokeyword.sample.demo_zhihu.entity.Article) ArrayList(java.util.ArrayList) HomeAdapter(me.yokeyword.sample.demo_zhihu.adapter.HomeAdapter) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 54 with LinearLayoutManager

use of android.support.v7.widget.LinearLayoutManager in project Carbon by ZieIony.

the class IconTextListItemActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_listcomponent);
    Samples.initToolbar(this, getString(R.string.iconTextListItemActivity_title));
    RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler);
    recycler.setLayoutManager(new LinearLayoutManager(this));
    RowListAdapter adapter = new RowListAdapter<>(DefaultIconTextItem.class, IconTextRow::new);
    adapter.addFactory(DefaultIconSearchItem.class, parent -> new IconSearchRow(parent, new ArraySearchDataProvider(new String[] {}), filterResults -> {
    }));
    recycler.setAdapter(adapter);
    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(new ColorDrawable(Carbon.getThemeColor(this, R.attr.carbon_dividerColor)), getResources().getDimensionPixelSize(R.dimen.carbon_1dip));
    dividerItemDecoration.setDrawRules(position -> position == 0);
    recycler.addItemDecoration(dividerItemDecoration);
    VectorDrawable drawable = new VectorDrawable(getResources(), R.raw.ic_face_24px);
    adapter.setItems(Arrays.asList(new DefaultIconSearchItem(this), new DefaultIconTextItem(drawable, "text"), new DefaultIconTextItem(drawable, "text"), new DefaultIconTextItem(drawable, "text"), new DefaultIconTextItem(drawable, "text")));
}
Also used : Arrays(java.util.Arrays) Bundle(android.os.Bundle) IconSearchRow(carbon.component.IconSearchRow) DividerItemDecoration(carbon.recycler.DividerItemDecoration) IconTextRow(carbon.component.IconTextRow) ColorDrawable(android.graphics.drawable.ColorDrawable) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultIconTextItem(carbon.component.DefaultIconTextItem) DefaultIconSearchItem(carbon.component.DefaultIconSearchItem) Carbon(carbon.Carbon) RecyclerView(carbon.widget.RecyclerView) SamplesActivity(tk.zielony.carbonsamples.SamplesActivity) VectorDrawable(carbon.drawable.VectorDrawable) R(tk.zielony.carbonsamples.R) RowListAdapter(carbon.recycler.RowListAdapter) Nullable(android.support.annotation.Nullable) ArraySearchDataProvider(carbon.widget.ArraySearchDataProvider) Samples(tk.zielony.carbonsamples.Samples) DefaultIconSearchItem(carbon.component.DefaultIconSearchItem) ColorDrawable(android.graphics.drawable.ColorDrawable) IconTextRow(carbon.component.IconTextRow) RowListAdapter(carbon.recycler.RowListAdapter) RecyclerView(carbon.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(carbon.recycler.DividerItemDecoration) DefaultIconTextItem(carbon.component.DefaultIconTextItem) IconSearchRow(carbon.component.IconSearchRow) VectorDrawable(carbon.drawable.VectorDrawable) ArraySearchDataProvider(carbon.widget.ArraySearchDataProvider)

Example 55 with LinearLayoutManager

use of android.support.v7.widget.LinearLayoutManager in project Carbon by ZieIony.

the class ImageTextSubtextDateListItemActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_listcomponent);
    Samples.initToolbar(this, getString(R.string.imageTextSubtextDateListItemActivity_title));
    RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler);
    recycler.setLayoutManager(new LinearLayoutManager(this));
    RowListAdapter adapter = new RowListAdapter<>(DefaultImageTextSubtextDateItem.class, ImageTextSubtextDateRow::new);
    adapter.addFactory(DefaultHeaderItem.class, PaddedHeaderRow.FACTORY);
    recycler.setAdapter(adapter);
    Drawable drawable = getResources().getDrawable(R.drawable.watermelon);
    String date = format.format(new Date().getTime());
    adapter.setItems(Arrays.asList(new DefaultHeaderItem("Header"), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date), new DefaultHeaderItem("Header"), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date)));
}
Also used : DefaultHeaderItem(carbon.component.DefaultHeaderItem) ImageTextSubtextDateRow(carbon.component.ImageTextSubtextDateRow) Drawable(android.graphics.drawable.Drawable) RowListAdapter(carbon.recycler.RowListAdapter) RecyclerView(carbon.widget.RecyclerView) DefaultImageTextSubtextDateItem(carbon.component.DefaultImageTextSubtextDateItem) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Date(java.util.Date)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1976 RecyclerView (android.support.v7.widget.RecyclerView)1085 View (android.view.View)822 TextView (android.widget.TextView)352 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)235 ArrayList (java.util.ArrayList)204 ImageView (android.widget.ImageView)186 Intent (android.content.Intent)150 Toolbar (android.support.v7.widget.Toolbar)134 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)131 GridLayoutManager (android.support.v7.widget.GridLayoutManager)125 BindView (butterknife.BindView)124 Bundle (android.os.Bundle)109 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)105 Nullable (android.support.annotation.Nullable)98 ViewGroup (android.view.ViewGroup)82 Context (android.content.Context)81 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)80 AdapterView (android.widget.AdapterView)70 List (java.util.List)69