Android开发头像挨着叠加效果
2021-01-08 本文已影响0人
你的益达233
一、效果图
头像挨着.png二、思路分析
叠加肯定用到FrameLayout,因为数量不一定,就需要动态addView。然后
headParams.leftMargin来设置偏移量
三、案例关键代码:
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)
}
关键是headParams.leftMargin思路