Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How keep aspect ratio in bitmap drawable

Tags:

android

How I can keep aspect ratio if I am using gravity fill_vertical or fill_horizontal? In this code:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/_toogle_green"
    android:gravity="bottom|fill_vertical"
/>

bitmap fills vertical, but in horizontal keeps original width and aspect ratio is broken.

I believe this question was asked, but I really can't find it, only for ImageView or ImageButton. But I need do that in drawables.

like image 776
neworld Avatar asked Sep 24 '12 08:09

neworld


1 Answers

Try this one:

<item>
     <bitmap
          android:gravity="center|bottom|clip_vertical"
          android:src="@drawable/your_image" />
</item>
like image 50
Ionut Negru Avatar answered Oct 03 '22 04:10

Ionut Negru