上图:
activity的代码:
/*
* 推荐关注的列表
* */
var recommendAdapter: RecommendAdapter? = null
var recommendBean = mutableListOf<RecommendBean>()
var manager: LinearLayoutManager = LinearLayoutManager(mContext)
manager.setOrientation(LinearLayoutManager.HORIZONTAL);
rv_recommend.layoutManager = manager
recommendAdapter = RecommendAdapter(arrayListOf())
recommendAdapter?.bindToRecyclerView(rv_recommend)
/*
- 返回数据的回调,根据你自己的情况给adapter赋值
*/
override fun recommendList(mutableList: MutableList<RecommendBean>?) {
recommendBean = mutableList!!
recommendAdapter?.setNewData(mutableList)
}
item的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="@drawable/bg_storke_white"
android:minWidth="117dp"
android:orientation="vertical"
android:paddingLeft="12dp"
android:paddingRight="12dp"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="11dp"
android:gravity="center_horizontal"
android:orientation="vertical">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/iv_header"
android:layout_width="61dp"
android:layout_height="61dp"
android:src="@drawable/logo"
app:riv_oval="true" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="双子女友高薪…"
android:textColor="@color/color_33"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="3dp"
android:text="猜你喜欢"
android:textColor="@color/color_b7"
android:textSize="10sp" />
<ImageView
android:id="@+id/iv_add"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginBottom="10dp"
android:padding="5dp"
android:src="@drawable/grzx_btn_gz" />
</LinearLayout>
</android.support.v7.widget.CardView>
bg_storke_white的代码:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white" />
<stroke
android:width="1dp"
android:color="@color/white"></stroke>
<corners android:radius="25dp" />
</shape>