Reputation: 1368
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.
Upvotes: 0
Views: 928
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
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
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