3

Is there any way to set border texture for LinearLayout or any other View? I can't just set an image as the background because of different screen sizes.

Here is the sample of the texture I'm talking about:

enter image description here

I tried to use Nine-patch, but it stretches the white lines that are supposed to be repeated.

Screenshot from Draw 9-patch tool:

enter image description here

Octavian Helm
  • 39,405
  • 19
  • 98
  • 102
Roman
  • 5,358
  • 9
  • 34
  • 43

1 Answers1

5

You can use shape drawable like this:

<shape android:shape="rectangle">
    <solid android:color="#FAFAD2" />           
    <stroke android:width="1sp" android:color="#000000"
        android:dashWidth="7sp" android:dashGap="5sp" />
</shape>

and this will result you something like this:

enter image description here

You can change color, width, border etc according to your requirements.

Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
  • I don't need solid color as background. It has to be a dark texture from the sample I linked above. – Roman Aug 16 '11 at 08:06
  • Then just make it the way you need it. This is _the_ only elegant solution for that problem. – Octavian Helm Aug 16 '11 at 08:15
  • But is it possible to set a texture as shape background? Or at least make it transparent? – Roman Aug 16 '11 at 08:23
  • 1
    Yay! I set `` and it worked. Thanks. Found the answer here - http://stackoverflow.com/questions/5646944/how-to-set-shapes-opacity – Roman Aug 16 '11 at 08:28