简体   繁体   中英

how to set the size of bitmap in drawable resource?

I've got the following drawable resource:

<layer-list>
    <item><shape>
            <gradient android:angle="225" android:endColor="#080517" android:startColor="#241c4d" />

            <stroke android:width="2.5dp" android:color="#FFFFFF" />

            <corners android:radius="5dp" />
        </shape></item>
        <item>
            <bitmap android:gravity="right|center_vertical" android:src="@drawable/tri_arrow_down_blue64" />
        </item>
</layer-list>

the problem is: I can not specify the exact size of the bitmap (in dp). as a result - the bitmap affects the height of a control with background set to that drawable.

I can workaround the problem by putting the control inside the FrameLayout, an extracting the bitmap portion of the drawable into an ImageView placed into the same FrameLayout. This solves the problem because ImageView can define the exact width and height of the bitmap (through layout_width and layout_height). But drawable does not have such (or similar) attributes. I wonder why this is so? and is there a more elegant way of specifying the size of a bitmap drawable right inside the drawable XML - instead of implementing that ugly workaround with FrameLayout?

thanks

I had a similar issue, and from my research there isn't a way to actually set the size of the item or bitmap in a layer list (which seems ridiculous).

I solved my problem simply by shrinking the size of the png image I was using for my bitmap drawable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM