【发布时间】:2014-11-22 08:43:26
【问题描述】:
我正在尝试在具有圆角边缘的 android 中创建视图。到目前为止我找到的解决方案是定义一个圆角形状并将其用作该视图的背景。
这是我所做的,如下定义一个可绘制对象:
<padding
android:top="2dp"
android:bottom="2dp"/>
<corners android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
现在我用它作为我的布局的背景,如下所示:
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:clipChildren="true"
android:background="@drawable/rounded_corner">
这很好用,我可以看到视图的边缘是圆角的。
但我的布局中有许多其他子视图,比如 ImageView 或 MapView。当我在上面的布局中放置一个ImageView 时,图像的角没有被剪裁/剪裁,而是显得完整。
我已经看到了其他解决方法,以使其像 here 解释的那样工作。
但是有没有一种方法可以为视图及其所有设置圆角 子视图包含在已舍入的主视图中 角落?
【问题讨论】:
-
如果您使用自定义布局扩展至 LinearLayout,并在创建其对象时,迭代该布局的所有子级并为其应用圆角边框背景?
-
android.support.v7.widget.CardView 似乎是解决这个问题的方法
-
这个解决方案为我解决了这个问题,但需要子类化:https://stackoverflow.com/questions/5574212/android-view-clipping
-
谷歌有新框架,新技术更好[Jetpack Compose][1] [1]:stackoverflow.com/questions/6054562/…
标签: android android-layout view android-view android-shape