Reputation: 3885
Hello all i want background of a layout as follows.
Now what i am doing is follows,
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@color/blue_new">
</item>
<item>
<rotate
android:fromDegrees="45"
android:toDegrees="0"
android:pivotX="0%"
android:pivotY="100%" >
<shape
android:shape="rectangle">
<solid android:color="@color/white" />
</shape>
</rotate>
</item>
<item>
<rotate
android:fromDegrees="-45"
android:toDegrees="0"
android:pivotX="130%"
android:pivotY="0%" >
<shape
android:shape="rectangle">
<solid android:color="@color/white" />
</shape>
</rotate>
</item>
</layer-list>
Now i am partially getting what i want. If i remove third item, the rectangle is not reaching another end. Is there any other way to do it? Other then 9patch image? Can i dynamically calculate the pivotX and pivoty values of the second and third item? Or is there any other method to do so.
Thanks.
Upvotes: 2
Views: 4692
Reputation: 529
maim.xml
<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".TestActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
style="@style/diagonalStyle">
</RelativeLayout>
style.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="diagonalStyle">
<item name="android:background">@drawable/background</item>
</style>
background.xml
<item>
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="50%"
android:pivotY="50%" >
<shape
android:shape="line"
android:top="1dip" >
<stroke
android:width="1dip"
android:color="#FF0000" />
</shape>
</rotate>
try this, it works
Upvotes: 1
Reputation: 1287
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@android:color/black">
</item>
<item>
<rotate
android:fromDegrees="55"
android:pivotX="10%"
android:pivotY="85%"
>
<shape
android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
</layer-list>
try this.
Upvotes: 3