Shafi
Shafi

Reputation: 1368

How to draw a layout of this type in android?

I want to provide a background drawable, similar to the one shown in the figure, to a layout. How can i do it using a drawable xml? Please suggest a suitable approach to go about this.

rectangleCutFromBottom

Upvotes: 0

Views: 928

Answers (2)

mjp66
mjp66

Reputation: 4213

I know this is 4+ years after the fact but for anyone else wanting to achieve the same result, there's a very simple way to achieve this by creating a layer-list xml drawable.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape>
            <padding
                android:top="5dp"
                android:left="5dp"
                android:right="5dp" />
            <solid
                android:color="@android:color/black" />
        </shape>
    </item>

    <item>
        <shape>
            <solid
                android:color="@android:color/white" />
        </shape>
    </item>

</layer-list>

Save this to your project's drawable folder and reference it like any other drawable (android:src / android:background, or programatically)

Upvotes: 0

Rahul Choudhary
Rahul Choudhary

Reputation: 3809

It is not possible to do this with single xml drawable but probably you can club two to create this effect. I would do it this way

  1. Create a drawable of square type with black borders
  2. Create a clip drawable and clip the bottom of sqaure drawable.

Reference here

http://developer.android.com/guide/topics/resources/drawable-resource.html#Clip

You can use the android:gravity="top" and then programmatically set the level to reveal 90% (or more) of the image

ImageView imageview = (ImageView) findViewById(R.id.image);
ClipDrawable drawable = (ClipDrawable) imageview.getDrawable();
drawable.setLevel(drawable.getLevel() + 9500);

Upvotes: 1

Related Questions