3

I am trying for repeat for buttons. I am able to get repeat for regular background type. But i was not able to find right, left and center using the repeat xml file.

If you know some solution with the xml file please help me.

Thanks in advance

The repeat xml file i have used is

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
        <bitmap
            android:src="@drawable/barslice"
            android:tileMode="repeat"
            android:dither="true"/>
</item>

The button i require is: left conrner

center

right corner

complete button i require

arnp
  • 3,178
  • 6
  • 26
  • 43

3 Answers3

3

you may get round-corner gradient buttons without even using images.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" >
        <shape>
            <solid
                android:color="#449def" />
            <stroke
                android:width="1dp"
                android:color="#2f6699" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
    <item>
        <shape>
            <gradient
                android:startColor="#449def"
                android:endColor="#2f6699"
                android:angle="270" />
            <stroke
                android:width="1dp"
                android:color="#2f6699" />
            <corners
                android:radius="4dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
</selector>

and simply set it as background to your button, textview or whatever you want

waqaslam
  • 67,549
  • 16
  • 165
  • 178
1

This will be nicely handled by 9 patch image. you will have an image like this

9 patch Image

and android will handle it automatically. Just set it as background of any button.

Note: image for other states like pressed, focused and disabled should also be provided otherwise it will not change buttons state.

Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
  • how can i repeat in a axis, like repeatX or repeatY. Now i need to repeat line vertically on the right corner. i have piece of line. i have tried with android:gravity="clip_vertical|right".but not working any idea – arnp Feb 07 '12 at 09:43