我的根视图中有一个FrameLayout(线性:垂直),我根据用户输入使用它来保存不同的片段。 FrameLayout小于背景,因此它似乎是“浮动”。
如何围绕FrameLayout的角落?
FrameLayout内部的碎片不是图片,所以我无法裁剪它们。
答案 0 :(得分:22)
创建一个xml文件,例如your_rounded_shape.xml
,在您的drawable文件夹中添加以下代码:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#CCCCCC"/>
<stroke android:width="2dp"
android:color="#999999"/>
<padding android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/>
<corners android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp"/>
</shape>
然后在your_rounded_shape.xml
中使用FrameLayout
作为背景。像这样:
<FrameLayout
android:width="match_parent"
android:height="wrap_content"
android:background="your_rounded_shape"/>
答案 1 :(得分:2)
用CardView布局替换FrameLayout。
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp">
</android.support.v7.widget.CardView>
答案 2 :(得分:0)
只是对以上答案的一种改进:
假设这个XML文件的名称为rounded_frame_layout.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#CCCCCC"/>
<stroke android:width="2dp"
android:color="#999999"/>
<padding android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/>
<corners android:radius="8dp"/>
</shape>
Then use your drawable as follows:
<FrameLayout
android:width="match_parent"
android:height="wrap_content"
android:background="@drawable/rounded_frame_layout"/>