繁体   English   中英

LinearLayout带有圆角和背景颜色

[英]LinearLayout with rounded corners and background color

CompileSdkVersion 26,如果它很重要。 我想创建带有圆角和背景颜色的LinearLayout。

我创建了2个LinearLayouts,一个有角,一个有颜色,但它们的形状与我的期望不符。

来自活动的代码

<LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/whitegrey"
            android:layout_marginTop="340dp"
            android:id="@+id/layout"
            android:layout_marginStart="10dp">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/custom_border"
            android:orientation="vertical"
            android:padding="6dp"
            android:textColor="@color/black">
    ...
    </LinearLayout>
    </LinearLayout>

custom_border.xml:

<?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
        <corners android:radius="20dp"/>
        <padding android:left="8dp" android:right="8dp" android:top="8dp" android:bottom="8dp"/>
        <stroke android:width="2dp" android:color="#444444" />
    </shape>

实际上,有圆形边框,后面有矩形布局,目标颜色。 我想填充目标颜色只有内部边界。 有没有办法设置填充颜色,最好是在custom_border.xml中?

在这里,我现在所拥有的:
在这里,我现在拥有的

在这里,我想要实现的目标:
在这里,我想要实现的目标

从手机查看,左边的字母被切断:
从手机查看,左侧的字母被切断

从您提供给我们的代码示例中,我似乎没有必要使用两个LinearLayout。 只需要使用android:background="@drawable/custom_border"的布局。

要获得预期的结果,只需将属性<solid android:color="@color/whitegrey" />custom_border.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <corners android:radius="20dp"/>
    <padding android:left="8dp" android:right="8dp" android:top="8dp" android:bottom="8dp"/>
    <stroke android:width="2dp" android:color="#444444" />
    <solid android:color="@color/whitegrey" />
</shape>

我希望我能帮到你!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM