具有圆角xml形状的蒙版布局 [英] Mask layout with rounded corner xml shape

查看:224
本文介绍了具有圆角xml形状的蒙版布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个LinearLayout:

I have this 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>

我想用圆角遮盖它,像这样:

And I want to mask it with rounded corner, like this:

我试图将其放置在具有Shape.xml之上的另一个布局的FrameLayout中,

I tried to put it in a FrameLayout with another layout with shape.xml on top of it,

但是我得到的最多是:

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

I'm looking for a way to use shape.xml background,

但是边框内部是透明的,外面是白色.

But with transparent inside the border, and white color outside.

我的shape.xml:

My 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的顶部.这是一种常见的做法.

Create a nine-patch with white rounded corners outside, transparent in the middle, ("inverse nine-patch") and put it on top on your LinearLayout. This is a common practice.

这篇关于具有圆角xml形状的蒙版布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆