Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Offset shape within a ShapeDrawable

I'm trying to draw a rounded rectangle with a border around it using a class that extends ShapeDrawable (see here) and everything is working except that the shapedrawable seems to be cutting off some of the border because the shape itself doesn't extend outside those bounds.

Is there not some way to offset where the shapedrawable starts drawing so that there is some padding between the bounds of the shape itself and the canvas? I have tried both ShapeDrawable.setBounds to larger than the intrinsic size of the shape and ShapeDrawable.setPadding but don't seem to be getting anywhere. Should I be subclassing Drawable instead?

like image 364
Stev_k Avatar asked Sep 09 '10 02:09

Stev_k


1 Answers

You can wrap you shape drawable with inset (inset_shape.xml):

    <inset xmlns:android="http://schemas.android.com/apk/res/android"
     android:drawable="@drawable/your_shape_drawable" android:insetBottom="10dip"
     android:insetLeft="10dip" android:insetRight="10dip" android:insetTop="10dip"
     android:visible="true" />

Then just use the inset_shape as you need.

like image 158
Konstantin Burov Avatar answered Nov 07 '22 09:11

Konstantin Burov