Drawable shape not showing when used in combination with android:drawableBottom attribute.

后端 未结 2 1939
遇见更好的自我
遇见更好的自我 2020-12-15 08:46

XML file saved at res/drawable/gradient_box.xml:




        
相关标签:
2条回答
  • 2020-12-15 08:57

    If you are using an ImageView to host the line shape as part of the "android:src" attribute, you will also run into the same problem unless you specify the width and height as part of the shape xml. One workaround is to host the line shape as part of the "android:background" attribute of ImageView. This way, you can make use of the size attributes of the ImageView for the line shape to "show" through.

    0 讨论(0)
  • 2020-12-15 09:10

    Solved it! The problem seems to be that a shape does not necessarily have intrinsic bounds. That is, the resulting drawable doesn't know how to draw itself!

    To solve this problem, simply specify the size of the shape, like this:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient
            android:startColor="#FFFF0000"
            android:endColor="#80FF00FF"
            android:angle="45"/>
        <padding android:left="7dp"
            android:top="7dp"
            android:right="7dp"
            android:bottom="7dp" />
        <corners android:radius="8dp" />
        <size android:width="xxdp"
              android:height="xxdp"/>
    </shape>
    

    When the shape was specified as a background drawable for the TextView, its dimensions was known to be the same as the TextView dimensions. When telling the shape to go to the right or above the TextView, the shape dimensions could not be determined automatically.

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