Android重叠的个人资料照片视图

时间:2018-11-22 09:16:36

标签: android android-linearlayout android-imageview

我正在尝试实现此视图。

enter image description here

我尝试过这种方式。

<LinearLayout
            android:id="@+id/images"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_gravity="center_horizontal"
            android:gravity="center_horizontal"
            android:layout_marginTop="10dp">

            <com.mikhaellopez.circularimageview.CircularImageView
                android:id="@+id/image1"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:src="@drawable/profile_default"
                app:civ_border_width="1dp"
                app:civ_border_color="@color/white_two"
                app:civ_shadow="false"/>

            <com.mikhaellopez.circularimageview.CircularImageView
                android:id="@+id/image2"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:src="@drawable/profile_default"
                android:layout_marginStart="-10dp"
                app:civ_border_width="1dp"
                app:civ_border_color="@color/white"
                app:civ_shadow="false"/>

        </LinearLayout>

但是第二张图片仍保持在第一张图片之上,而我想反过来。我会以编程方式添加图像,所以我认为我不能使用RelativeLayout。这可能吗,或者已经有一个现有的Android库?

2 个答案:

答案 0 :(得分:0)

您可以尝试在第一个代码中使用android:elevation="8dp",使第二个视图成为第一个视图

答案 1 :(得分:0)

这就是我以编程方式生成图像的方式。

enter image description here

 val circleImageView1 = CircleImageView(context)
        circleImageView1.layoutParams = LinearLayout.LayoutParams(Tools.dpToPx(40), Tools.dpToPx(40))
        circleImageView1.borderWidth = 1
        circleImageView1.borderColor = ContextCompat.getColor(context, R.color.white_two)
        circleImageView1.circleBackgroundColor = ContextCompat.getColor(context, R.color.blue)
        circleImageView1.setImageResource(R.drawable.profile_default)

        val layoutParams = LinearLayout.LayoutParams(Tools.dpToPx(40), Tools.dpToPx(40))
        layoutParams.setMargins(Tools.dpToPx(-10), 0, 0, 0)

        val circleImageView2 = CircleImageView(context)
        circleImageView2.layoutParams = layoutParams
        circleImageView2.borderWidth = 1
        circleImageView2.borderColor = ContextCompat.getColor(context, R.color.white_two)
        circleImageView2.circleBackgroundColor = ContextCompat.getColor(context, R.color.red)
        circleImageView2.setImageResource(R.drawable.profile_default)

        val circleImageView3 = CircleImageView(context)
        circleImageView3.layoutParams = layoutParams
        circleImageView3.borderWidth = 1
        circleImageView3.borderColor = ContextCompat.getColor(context, R.color.white_two)
        circleImageView3.circleBackgroundColor = ContextCompat.getColor(context, R.color.green)
        circleImageView3.setImageResource(R.drawable.profile_default)

        itemView.images.addView(circleImageView1)
        itemView.images.addView(circleImageView2)
        itemView.images.addView(circleImageView3)

        itemView.images.scaleX = -1.0f

这暂时有效,因为顺序很重要,我只需要确保反向浏览图像列表即可。