首页 > 解决方案 > ImageView拒绝父级的圆角和边框

问题描述

我有多个孩子的视图我想给整个小组这样的圆角:

在此处输入图像描述

我试图通过它们的背景给父 LinearLayout 和它的 ImageView 圆角来做到这一点

线性布局和孩子:

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="20dp"
            android:layout_marginRight="20dp"
            android:background="@drawable/tile_background"
            android:elevation="1dp"
            android:orientation="vertical">


            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/image_frame_sponsorship"
                android:coverTileUrl="@{sponsorship.coverTileUri}">

            </ImageView>


            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:gravity="center_vertical"
                android:paddingLeft="20dp">

                <TextView
                    android:id="@+id/postActionText"
                    style="@style/ActionFont"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="6dp"
                    tools:text="@string/watch_respond">

                </TextView>

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:src="@drawable/ic_chevron_right_black_36dp">

                </ImageView>


            </RelativeLayout>


        </LinearLayout>

线性布局背景:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#FFFFFF" />
    <stroke
        android:width="1dp"
        android:color="#D2DADC" />
    <corners android:radius="10dp" />
    <padding
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp" />
</shape>

ImageView 背景:

  <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <corners
                android:topLeftRadius="10dp"
                android:topRightRadius="10dp"/>
            <solid android:color="@android:color/white" />

            <stroke
                android:width="1dp"
                android:color="@color/white" />
        </shape>

LinearLayout 采用圆角,但 imageView 的前两个角没有,溢出角,显然是其父级的边框:

在此处输入图像描述

如何使 ImageView 表现良好?

标签: androidxmlandroid-layout

解决方案


使imageview的所有角落都变圆。底部将隐藏在线性布局的后面。


推荐阅读