带圆角的遮罩布局XML形状

3

我有一个线性布局:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ImageView
        android:layout_width="100dp"
        android:layout_height="70dp"
        android:src="@drawable/ic_launcher"
        android:scaleType="centerCrop"/>

    <TextView
        android:layout_width="100dp"
        android:layout_height="30dp"
        android:background="#FFD800"
        android:textColor="@android:color/black"
        android:gravity="center"
        android:text="Text View"/>
</LinearLayout>

enter image description here

我想把它变成圆角的,就像这样:

enter image description here

我试过将其放入一个FrameLayout中,并在其上方放置另一个具有shape.xml的布局,

但最终我得到的是:

enter image description here

或者

enter image description here

我正在寻找一种使用shape.xml背景的方法,

但在边框内部透明,在外部为白色。

我的shape.xml:

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
    android:color="#FFFFFF">
</solid>

<stroke
android:width="2dp"
android:color="#000000" >
</stroke>

<padding
    android:left="5dp"
    android:top="5dp"
    android:right="5dp"
    android:bottom="5dp">
</padding>

<corners
    android:radius="50dp">
</corners>
</shape>

你想用圆角 XML 遮盖整个布局吗?请发布您的整个 XML 布局文件代码。 - GrIsHu
@GrlsHu 是的,我想用corner xml来遮盖整个布局。(添加了我的布局) - David
看看我的回答。@David - GrIsHu
4个回答

6

创建一个带有白色圆角外边框,中间透明的九宫格图案(“反向九宫格”),并将其置于您的LinearLayout顶部。这是一个常见的做法。


不知道这是否是最好的答案,但它是唯一真正有效的。谢谢。 - David

0

尝试了下面的 XML 文件

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <stroke
        android:width="1dp"
        android:color="#4a6176" />

    <padding
        android:left="10dp"
        android:right="10dp"
         />

    <corners android:radius="6dp" />

</shape>

0

只需从形状中删除<solid>标签。然后将该形状应用于您的LinearLayout的背景。

因为<solid>标签指定了形状的填充颜色。 没有该标签,形状的中心将完全透明。 因此它看起来就像一个边框。


-2

将您的布局背景设置为以下内容:android:background="@drawable/shape"


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接