Border texture for a View

2019-02-25 04:16发布

问题:

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:

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

Screenshot from Draw 9-patch tool:

回答1:

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:

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