2016-03-24 90 views
7

我在我的根视图(线性:垂直)内部有一个FrameLayout,我用它来根据用户输入保存不同的片段。 FrameLayout比背景小,所以它看起来是“浮动的”。带圆角的FrameLayout

我该如何绕过FrameLayout的角落?

进入FrameLayout的碎片不是图片,所以我不能裁剪它们。

+0

难道你不能只是抛出一个手工制作的drawable作为你的FrameLayout的背景吗? – m02ph3u5

+0

看看这个http://www.gadgetsaint.com/tips/rounded-corners-views-layouts-android/#.WPz2QVN97BI – ASP

回答

11

创建一个xml文件,例如your_rounded_shape.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: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"/> 
+0

这是完美的!谢谢,这正是我正在寻找的。 –