android - 具有圆角 xml 形状的掩码布局

标签 android xml shapes mask

我有这个 LinearLayout:

<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>

最佳答案

创建一个外部有白色圆角、中间透明的九补丁(“反向九补丁”)并将其放在 LinearLayout 的顶部。这是一种常见的做法。

关于android - 具有圆角 xml 形状的掩码布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25762867/

相关文章:

android - smali 函数 : Return an Integer

android - 选择日期范围内的元素

android - EditText 的提示被切断,因为我的提示文本超过一行。 editText 只显示一行。我怎样才能使整个提示可见?

python - 使用 multiprocessing.Pool 泄漏内存,即使在 close() 之后

Python:根据 1 和 0 的数组计算结构的面积和周长

android - 按钮不会改变其在选择器中的形状

java - 没有方法签名 : com. android.build.gradle.AppPlugin.getNdkFolder()

java - 谷歌地图 v2 简单应用程序不工作

java - JAXBContextFactory hell - java.lang.ClassNotFoundException : com. ibm.xml.xlxp2.jaxb.JAXBContextFactory

android - 可绘制的形状是不可见的