简体   繁体   中英

How rotate Rectangle in Android XML?

I'm trying to change a rectangle shape from its vertical to horizontal in an Android app with the XML, but it is not working. It simply draws a horizontal shape without its oval shape.

main.xml:

<item>

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <solid android:color="#5ebb1e" />

    </shape>
</item>

<item
    android:bottom="400dp"
    android:left="-100dp"
    android:right="-100dp"
    android:top="-200dp">
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
        <gradient
            android:angle="90"
            android:endColor="#65FFFFFF"
            android:startColor="#65FFFFFF" />
    </shape>
</item>
<item
    android:bottom="402dp"
    android:left="-100dp"
    android:right="-100dp"
    android:top="-280dp">
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
        <solid android:color="#2a2a2a" />
    </shape>
</item>

Output

To Change

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

        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle"

            >
            <solid android:color="#5ebb1e"  />

        </shape>
    </item>
    <item
        android:right="200dp"
        android:left="-160dp"
        android:top="0dp"
        >
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval"
            >
            <gradient
                android:angle="90"
                android:endColor="#65FFFFFF"
                android:startColor="#65FFFFFF" />
        </shape>
    </item>

    <item
        android:right="200dp"
        android:left="-200dp"

        android:top="0dp">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">
            <solid android:color="#2a2a2a" />
        </shape>
    </item>
</layer-list>

just change your left -right top -bottom

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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