Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android bitmap image size in XML

In my XML file, I'm using bitmap as the following

<bitmap     android:src="@drawable/Icon"     android:gravity="center"/> 

Here the image width of the icon exceeds the screen.

I tried android:width="100dp" and all. But it isn't working.

Complete XML file:

<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >     <item>       <shape android:shape="rectangle">             <stroke android:width="3dp" android:color="@color/black" />             <solid android:color="@color/bg_green" />         </shape>    </item>    <item>     <bitmap         android:src="@drawable/Icon"         android:gravity="center"/>     </item> </layer-list> 

How can I reduce the width and height of the above bitmap?

like image 492
Erma Isabel Avatar asked Apr 15 '14 09:04

Erma Isabel


People also ask

How do I get bitmap from imageView?

Bitmap bm=((BitmapDrawable)imageView. getDrawable()). getBitmap(); Try having the image in all drawable qualities folders (drawable-hdpi/drawable-ldpi etc.)

What is the bitmap in Android?

A bitmap is simply a rectangle of pixels. Each pixel can be set to a given color but exactly what color depends on the type of the pixel. The first two parameters give the width and the height in pixels. The third parameter specifies the type of pixel you want to use.


1 Answers

Only API 23 or later

Just use

<item     android:width="200dp"     android:height="200dp"     android:drawable="@drawable/splash_background"     android:gravity="center" /> 

instead

<item     android:left="200dp"     android:right="200dp">      <bitmap         android:src="@drawable/splash_background"         android:gravity="center" />  </item> 
like image 153
MaxF Avatar answered Oct 13 '22 04:10

MaxF