Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: drawing an "X" using shape

A need to draw an "X" in a View using Shapes, but the X's edges must be anchored on left, top, right and bottom of the view.

Something like this:

sample image

like image 933
Christian Avatar asked Jun 18 '12 16:06

Christian


1 Answers

By xml at drawable:

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

<item>
    <rotate
        android:fromDegrees="135"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="135">
        <shape android:shape="line">
            <stroke android:width="1dp" android:color="@color/social_grey" />
        </shape>
    </rotate>
</item>
<item>
    <rotate
        android:fromDegrees="45"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="45">
        <shape android:shape="line">
            <stroke android:width="1dp" android:color="@color/social_grey" />
        </shape>
    </rotate>
</item>


</layer-list>

With padding:

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

<item
   android:left="4dp"
    android:right="4dp"
    >
    <rotate
        android:fromDegrees="135"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="135">
        <shape android:shape="line">
            <stroke android:width="1dp" android:color="@color/social_grey" />
        </shape>
    </rotate>
</item>
<item
    android:left="4dp"
    android:right="4dp"
    >
    <rotate
        android:fromDegrees="45"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="45">
        <shape android:shape="line">
            <stroke android:width="1dp" android:color="@color/social_grey" />
        </shape>
    </rotate>
</item>
</layer-list>
like image 149
Shlomi Fresko Avatar answered Nov 15 '22 06:11

Shlomi Fresko