2

Hello all i want background of a layout as follows.

enter image description here

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.

Mercurial
  • 3,615
  • 5
  • 27
  • 52

2 Answers2

3
        <?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.

Jossy Paul
  • 1,267
  • 14
  • 26
1

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

Sumit Pathak
  • 529
  • 2
  • 7
  • 24
  • yes ... work ... with statics "Degrees" if you want apply in a design without images you need be a mage ( example : https://i.ytimg.com/vi/UwTSuGHGi_Y/maxresdefault.jpg ) –  Dec 21 '15 at 10:00