
我们看效不雅和GridLayoutManager没有什么差别呢,那我们啻小小的修改一下,你就可以看到它的强大年夜。
我们给每个item的构造参加margin:
- <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="5dp"
- android:background="@color/colorAccent">
- <TextView
- android:id="@+id/tv"
- android:layout_width="100dp"
- android:layout_height="100dp"
- android:layout_gravity="center"
- android:gravity="center"
- android:textColor="#fff"
- /></LinearLayout>
然后我们在适配器的onBindViewHolder办法中为我们的item设置个随机的高度:
- //贴上部分代码,其余的请看附件
- private List<Integer> mHeights;
- public RecyclerAdapter(Context context, List<String> mDatas) {
- this.context = context;
- this.mDatas = mDatas;
- mHeights = new ArrayList<Integer>();
- for (int i = 0; i < mDatas.size(); i++) {
- mHeights.add((int) (100 + Math.random() * 300));
- }
- }
- @Override
- public void onBindViewHolder(MyViewHolder holder,
推荐阅读
Windows 10计划任务怎么用?教你轻松玩转Windows 10自带任务计划
【技巧沙龙】AI开辟者拭魅战营-7分钟打造1个定制技能。7月22号,我们等你一路! Win10筹划义务怎么竽暌姑?义务筹划是Windows操作体系异常强大年夜的一个功能,应用义务筹划,我们可以将任>>>详细阅读
地址:http://www.17bianji.com/lsqh/36229.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示