一泞辐、效果圖
頭像挨著.png
二笔横、思路分析
疊加肯定用到FrameLayout,因?yàn)閿?shù)量不一定,就需要?jiǎng)討B(tài)addView咐吼。然后
headParams.leftMargin來(lái)設(shè)置偏移量
三狠裹、案例關(guān)鍵代碼:
xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/white_circle"
>
<ImageView
android:id="@+id/iv_head_small"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:scaleType="centerCrop" />
</FrameLayout>
java代碼:
for (i in dataBean.user_items.indices) {
val headParams = FrameLayout.LayoutParams(UtilHelper.dip2px(mActivity, 26f), UtilHelper.dip2px(mActivity, 26f))
val headGroupView = UtilHelper.inflate(mActivity!!, R.layout.layout_ceo_data_head)
headParams.leftMargin = (dataBean.user_items.size - i - 1) * UtilHelper.dip2px(mActivity, 20f)
headGroupView.layoutParams = headParams
val headView = headGroupView.findViewById<ImageView>(R.id.iv_head_small)
GlideHelper.load(mActivity!!, dataBean.user_items[i].img!!, headView, 7)
fl_user_heads?.addView(headGroupView)
}
關(guān)鍵是headParams.leftMargin思路