一、效果图
item平分.png二、思路分析
没什么好分析的,可以addItemDecoration在里面处理
三、案例代码:
布局文件:
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_learn_direction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/tv_select_number_limit"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:visibility="gone"
/>
item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tv_study_tag"
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center"
android:textColor="@color/c_33"
android:textSize="@dimen/m_size_16"
android:background="@drawable/login_study_plan_tag_r4dp_selector"
android:maxLines="1"
android:ellipsize="end"
android:maxEms="5"
android:paddingLeft="8dp"
android:paddingRight="8dp">
</TextView>
Activity中代码
在初始化中:
rv_learn_direction.layoutManager = GridLayoutManager(mActivity,3)
rv_learn_direction.addItemDecoration(object :RecyclerView.ItemDecoration(){
override fun getItemOffsets(outRect: Rect, itemPosition: Int, parent: RecyclerView?) {
super.getItemOffsets(outRect, itemPosition, parent)
outRect.right = UtilHelper.dip2px(mActivity,16f)
outRect.bottom = UtilHelper.dip2px(mActivity,16f)
}
})
基本看懂了吧,没啥,假如帮到有需要的人呢
网友评论