You can use rotate
and layer-list
to get the effect totally in xml without any java code. The following is the example, but in order to let it display more elegantly, you have to re-calculate the height, width and pick a better angle to rotate.
debit_card.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="10dp">
<shape>
<solid android:color="#ffff0000"></solid>
<size
android:width="100dp"
android:height="50dp"></size>
</shape>
</item>
<item>
<rotate
android:fromDegrees="-27"
android:pivotX="100%"
android:pivotY="0">
<shape android:shape="rectangle">
<size
android:width="100dp"
android:height="50dp"></size>
<solid android:color="#ff00ff00"></solid>
</shape>
</rotate>
</item>
</layer-list>
Then you can use the drawable above in a ImageView
, the layout size properties must be wrap_content/wrap_content
.
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/debit_card" />
</FrameLayout>
The final effect will look like the picture following.
