我有这个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>
我想用圆角掩盖它,就像这样:
我试图把它放在一个FrameLayout中,另一个布局上面有shape.xml,
但我得到的最多的是:
或
我正在寻找使用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>
答案 0 :(得分:4)
创建一个外部带有白色圆角的九个补丁,中间是透明的(“反九补丁”)并将其放在LinearLayout的顶部。这是一种常见的做法。
答案 1 :(得分:0)
只需从形状中删除<solid>
标记即可。然后将该形状应用于LinearLayout
的背景。
因为<solid>
标签指定了您的形状的填充颜色。
如果没有该标签,您的形状中心将完全透明。
所以它看起来就像一个边界。
答案 2 :(得分: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>
答案 3 :(得分:-1)
使您的布局背景如下:android:background="@drawable/shape"