Relatively diagonal spray pattern background

Hi everyone, I want the background of the layout to look like this.

enter image description here

Now what I do should be

<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 partially get what I want. If I remove the third element, the rectangle will not reach the other end. Is there any other way to do this? Other then 9x image? Can I dynamically calculate pivotX values ​​and values ​​for the second and third elements? Or is there any other way to do this.

Thanks.

0
source share
2 answers
  <?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 it.

+2
source

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

0
source

All Articles