【发布时间】:2018-12-20 06:41:34
【问题描述】:
我已经使用 Imageview 创建了布局,并设置了带有圆角半径的自定义背景,父布局是拐角的,但 Imageview 不是圆角的。我怎样才能做到这一点?
提前致谢。
bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid
android:color="@color/list_item_bg"/>
<stroke
android:width="2dp"
android:color="@color/colorAccent" />
<corners
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
</shape>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_item_bg"
>
<ImageView
android:id="@+id/food_image"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:scaleType="centerCrop"
android:clipToOutline="true"
android:background="@drawable/image_bg"
android:src="@drawable/sample_image"/>
</LinearLayout>
【问题讨论】:
-
分享你的布局代码。
-
这应该有助于link
标签: android android-layout rounded-corners