0
votes

I am searching for solving this problem but I found nothing for hours. I need to draw on a view a LinearLayout having a border with a particular texture and a transparent body. A good solution should be a shape, but the only thing I can do with it is a flat-color border.

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <stroke
        android:width="5dp"
        android:color="#DDDDDD" />
</shape>

enter image description here

Is there a way for having a texture for that stroke rather than a color (also writing shape programmatically)?

1
use a BitmapShader or LinearGradient as a Shader to your Paint objectpskink
can you show me a small example?Massimo
extend LinearLayout and override its dispatchDrawpskink

1 Answers

0
votes

You can create you custom ShapeDrawable. One way how to achieve the effect is to define your custom paint and apply a bitmapshader on it..This will work ok for simple and repeating texture.

Another way is to directly draw the the bitmap (or whatever you want) to the canvas (in the onDraw method of your custom drawable) and then draw second time with PorterDuffMode Clear enabled. You should basically draw a smaller "blank" Rect into the first one).