recylerView



1.
在item嵌套东西

屏幕快照 2015-11-13 00.33.46.png
使得使得有分隔效果

    <android.support.v7.widget.CardView

        style="@style/CardView.Light"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_margin="5dp"


        >


        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:orientation="horizontal"

            >


            <ImageView

                android:id="@+id/item_list_iv"

                android:layout_width="64dp"

                android:layout_height="64dp"

                android:layout_margin="8dp"/>


            <TextView

                android:id="@+id/item_list_tv"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_gravity="center_vertical"

                android:text="内容"

                android:textSize="24sp"/>

        </LinearLayout>

    </android.support.v7.widget.CardView>


2.修改布局管理器从大到ListView,GridView,瀑布流的效果


    private void initList()

    {

        //实现listView的效果

        // 可以垂直滑动,也可以水平滑动,数据反向加载


        //设置布局管理器

        LinearLayoutManager layoutManager = new LinearLayoutManager(this,

                                                                    LinearLayoutManager.VERTICAL,

                                                                    false);

        mRecyclerView.setLayoutManager(layoutManager);


        //设置adapter

        mRecyclerView.setAdapter(new ListAdapter(this,

                                                 mListDatas));//adapter ---> list数据

    }


    private void initGrid()

    {

        //实现listView的效果

        // 可以垂直滑动,也可以水平滑动,数据反向加载


        //设置布局管理器

        GridLayoutManager layoutManager = new GridLayoutManager(this,

                                                                2,

                                                                GridLayoutManager.VERTICAL,

                                                                false);

        mRecyclerView.setLayoutManager(layoutManager);


        //设置adapter

        mRecyclerView.setAdapter(new ListAdapter(this,

                                                 mListDatas));//adapter ---> list数据

    }


    private void initStragger()

    { 

        //实现listView的效果

        // 可以垂直滑动,也可以水平滑动,数据反向加载


        //设置布局管理器

        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,

                                                                                  StaggeredGridLayoutManager.VERTICAL);


        mRecyclerView.setLayoutManager(layoutManager);


        //设置adapter

        mRecyclerView.setAdapter(new StraggerdAdpater(this,

                                                      mStraggerDatas));//adapter ---> list数据

    }



3.瀑布了需要改item的样式Card

屏幕快照 2015-11-13 00.42.16.png




4.下拉刷新:

在外面套一层----------

 <android.support.v4.widget.SwipeRefreshLayout

        android:id="@+id/srl"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        >


        <android.support.v7.widget.RecyclerView

            android:id="@+id/rv"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            />

    </android.support.v4.widget.SwipeRefreshLayout>



 @Override

    public void onRefresh()

    {

        //下拉刷新时的回调

        new AsyncTask<Void, Void, Void>()

        {


            @Override

            protected Void doInBackground(Void... params)

            {

                try

                {

                    Thread.sleep(3000);

                } catch (InterruptedException e)

                {

                    e.printStackTrace();

                }


                RecyclerView.Adapter adapter = mRecyclerView.getAdapter();


                if (adapter instanceof ListAdapter)

                {

                    //list加载数据

                    for (int i = 0; i < mListIcons.length; i++)

                    {

                        DataBean bean = new DataBean();

                        bean.icon = mListIcons[i];

                        bean.content = "内容-" + i;


                        mListDatas.add(bean);

                    }

                } else if (adapter instanceof StraggerdAdpater)

                {

                    //stragger加载数据

                    for (int i = 0; i < mStraggeredIcons.length; i++)

                    {

                        DataBean bean = new DataBean();

                        bean.icon = mStraggeredIcons[i];

                        bean.content = "内容-" + i;


                        mStraggerDatas.add(bean);

                    }

                }

                return null;

            }


            @Override

            protected void onPostExecute(Void aVoid)

            {

                super.onPostExecute(aVoid);


                RecyclerView.Adapter adapter = mRecyclerView.getAdapter();

                //adatper刷新

                adapter.notifyDataSetChanged();

                //通知刷新的view刷新完成

                mRefreshLayout.setRefreshing(false);


            }

        }.execute();


    }










1.
在item嵌套东西

屏幕快照 2015-11-13 00.33.46.png
使得使得有分隔效果

    <android.support.v7.widget.CardView

        style="@style/CardView.Light"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_margin="5dp"


        >


        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:orientation="horizontal"

            >


            <ImageView

                android:id="@+id/item_list_iv"

                android:layout_width="64dp"

                android:layout_height="64dp"

                android:layout_margin="8dp"/>


            <TextView

                android:id="@+id/item_list_tv"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_gravity="center_vertical"

                android:text="内容"

                android:textSize="24sp"/>

        </LinearLayout>

    </android.support.v7.widget.CardView>


2.修改布局管理器从大到ListView,GridView,瀑布流的效果


    private void initList()

    {

        //实现listView的效果

        // 可以垂直滑动,也可以水平滑动,数据反向加载


        //设置布局管理器

        LinearLayoutManager layoutManager = new LinearLayoutManager(this,

                                                                    LinearLayoutManager.VERTICAL,

                                                                    false);

        mRecyclerView.setLayoutManager(layoutManager);


        //设置adapter

        mRecyclerView.setAdapter(new ListAdapter(this,

                                                 mListDatas));//adapter ---> list数据

    }


    private void initGrid()

    {

        //实现listView的效果

        // 可以垂直滑动,也可以水平滑动,数据反向加载


        //设置布局管理器

        GridLayoutManager layoutManager = new GridLayoutManager(this,

                                                                2,

                                                                GridLayoutManager.VERTICAL,

                                                                false);

        mRecyclerView.setLayoutManager(layoutManager);


        //设置adapter

        mRecyclerView.setAdapter(new ListAdapter(this,

                                                 mListDatas));//adapter ---> list数据

    }


    private void initStragger()

    { 

        //实现listView的效果

        // 可以垂直滑动,也可以水平滑动,数据反向加载


        //设置布局管理器

        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,

                                                                                  StaggeredGridLayoutManager.VERTICAL);


        mRecyclerView.setLayoutManager(layoutManager);


        //设置adapter

        mRecyclerView.setAdapter(new StraggerdAdpater(this,

                                                      mStraggerDatas));//adapter ---> list数据

    }



3.瀑布了需要改item的样式Card

屏幕快照 2015-11-13 00.42.16.png




4.下拉刷新:

在外面套一层----------

 <android.support.v4.widget.SwipeRefreshLayout

        android:id="@+id/srl"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        >


        <android.support.v7.widget.RecyclerView

            android:id="@+id/rv"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            />

    </android.support.v4.widget.SwipeRefreshLayout>



 @Override

    public void onRefresh()

    {

        //下拉刷新时的回调

        new AsyncTask<Void, Void, Void>()

        {


            @Override

            protected Void doInBackground(Void... params)

            {

                try

                {

                    Thread.sleep(3000);

                } catch (InterruptedException e)

                {

                    e.printStackTrace();

                }


                RecyclerView.Adapter adapter = mRecyclerView.getAdapter();


                if (adapter instanceof ListAdapter)

                {

                    //list加载数据

                    for (int i = 0; i < mListIcons.length; i++)

                    {

                        DataBean bean = new DataBean();

                        bean.icon = mListIcons[i];

                        bean.content = "内容-" + i;


                        mListDatas.add(bean);

                    }

                } else if (adapter instanceof StraggerdAdpater)

                {

                    //stragger加载数据

                    for (int i = 0; i < mStraggeredIcons.length; i++)

                    {

                        DataBean bean = new DataBean();

                        bean.icon = mStraggeredIcons[i];

                        bean.content = "内容-" + i;


                        mStraggerDatas.add(bean);

                    }

                }

                return null;

            }


            @Override

            protected void onPostExecute(Void aVoid)

            {

                super.onPostExecute(aVoid);


                RecyclerView.Adapter adapter = mRecyclerView.getAdapter();

                //adatper刷新

                adapter.notifyDataSetChanged();

                //通知刷新的view刷新完成

                mRefreshLayout.setRefreshing(false);


            }

        }.execute();


    }









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值