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