java - Android -decrease imageview size with keeping aspect ratio -


i want decrease imageview's height as textview's height , keep it's aspect ratio. real size of image : 128*128

here code:

   <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:background="#b6006a"         android:gravity="center_horizontal"         android:orientation="horizontal">      <imageview         android:id="@+id/imageview1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:maxheight="10dp"         android:minheight="40dp"          android:maxwidth="40dp"                      android:layout_weight="1"         android:adjustviewbounds="true"                     android:padding="5dip"         android:scaletype="fitxy"         android:src="@drawable/icon" />      <textview         android:id="@+id/textview1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_weight="1"         android:background="#b6006a"                     android:padding="10dip"         android:text="new message"         android:textcolor="#fff"         android:textstyle="bold"         android:textsize="20dp" />      </linearlayout> 

and result : enter image description here

any suggestion?

hi use code resize image @ runtime.

public static bitmap decodesampledbitmapfromresource(resources res, int resid,int reqwidth, int reqheight) {      final bitmapfactory.options options = new bitmapfactory.options();     options.injustdecodebounds = true;     bitmapfactory.decoderesource(res, resid, options);      // calculate insamplesize     options.insamplesize = calculateinsamplesize(options, reqwidth, reqheight);      // decode bitmap insamplesize set     options.injustdecodebounds = false;     return bitmapfactory.decoderesource(res, resid, options); }  public static int calculateinsamplesize(             bitmapfactory.options options, int reqwidth, int reqheight) {     // raw height , width of image     final int height = options.outheight;     final int width = options.outwidth;     int insamplesize = 1;      if (height > reqheight || width > reqwidth) {          final int halfheight = height / 2;         final int halfwidth = width / 2;          // calculate largest insamplesize value power of 2 , keeps both height , width larger requested height , width.          while ((halfheight / insamplesize) > reqheight                 && (halfwidth / insamplesize) > reqwidth) {             insamplesize *= 2;         }     }      return insamplesize; } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -