Offset shape within a ShapeDrawable

后端 未结 2 2102
独厮守ぢ
独厮守ぢ 2021-02-14 05:55

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

相关标签:
2条回答
  • 2021-02-14 06:36

    Try this in your drawable...!

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >
    
        <solid android:color="#e1e1e1" />
    
        <stroke
            android:width="2dp"
            android:color="#808080" />
    
        <corners android:radius="10dp" />
    
        <padding
            android:bottom="5dp"
            android:left="5dp"
            android:right="5dp"
            android:top="5dp" />
    
    </shape>
    
    0 讨论(0)
  • 2021-02-14 06:45

    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.

    0 讨论(0)
提交回复
热议问题