Home > Net >  How to achieve custom shape match parent?
How to achieve custom shape match parent?

Time:01-02

I created custom shape in XML:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <layer-list>
            <item>
                <shape android:shape="rectangle">
                    <size android:width="160dp"/>
                    <size android:height="30dp"/>
                    <solid android:color="@color/white"/>
                    <padding android:right="15dp"/>
                    <stroke android:width="1dp" android:color="@color/main_color"/>
                    <corners android:radius="15dp"/>
                </shape>
            </item>

            <item
                android:drawable="@drawable/down_arrow_red"
                android:width="10dp"
                android:height="6dp"
                android:gravity="center|right"/>
        </layer-list>
    </item>

</selector>

Since match parent wasn't allowed while defining of width and height, I am worried how this shape will look like on different size screens. How to make this shape match parent screen? Thanks!

CodePudding user response:

I think what you want to ask is about sizing.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <item>
        <shape
            android:layout_width="match_parent"
            android:shape="rectangle">
            <size android:height="30dp" />
            <solid android:color="@color/white" />
            <padding android:right="15dp" />
            <stroke
                android:width="1dp"
                android:color="@color/teal_200" />
            <corners android:radius="15dp" />
        </shape>
    </item>

    <item
        android:width="10dp"
        android:height="6dp"
        android:drawable="@android:drawable/arrow_down_float"
        android:gravity="center|right" />
</layer-list>

enter image description here

  • Related