Resize bitmap inside a drawable layer-list

后端 未结 2 2036
清酒与你
清酒与你 2021-01-13 09:32

Currently I\'m developing a Android application. I want to make a text (a header) with a background that looks like this:

 _______
/______/

相关标签:
2条回答
  • 2021-01-13 09:41

    I solved it using two (half-transparant) images which represent the corners.

    The XML looks like this:

    <?xml version="1.0" encoding="UTF-8"?> 
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
            <item>
                    <shape>    
                        <gradient
                          android:startColor="@color/jaarkleur"
                          android:centerColor="@color/jaarkleur"
                          android:endColor="#E66C2C00"
                          android:angle="0" />
                        <stroke android:width="1dp"
                android:color="#ff000000"
                />       
                    </shape>
            </item>
            <item>
                <bitmap android:src="@drawable/overlay_left" android:gravity="left|top"  />
            </item>
            <item>
                <bitmap android:src="@drawable/overlay_right" android:gravity="right|bottom" />
            </item>        
    </layer-list>
    
    0 讨论(0)
  • 2021-01-13 10:00

    Instead of using a layer-list with gradient / border stroke and a custom image, consider using a NinePatchDrawable.

    There is also a handy 9-patch creater that comes with the android SDK.

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