android - How to set image in ImageView to right proportions -
look @ picture below.
i'm loading image sdcard code belove.
i cannot picture automatically fill imageview. set background color green highlight problem. have tried many android:scaletype center , fit_xy but.
im using insamplesize = 8 how can imageview automatically scale image in right hight/width proportions , fill screen
also thing, see exittext , button placed above imageview(i think). want them under , not block imageview. maybe misunderstand android layout technical.
drawview.java
public class drawview extends imageview { private context ctx; public drawview(context context, attributeset atts) { super(context, atts); this.ctx = context; } @override protected void ondraw(canvas canvas) { string filepath = environment.getexternalstoragedirectory().tostring() + "/ptppservice/163693fe-7c48-4568-a082-00047123b9f1.2.imag2200.jpg"; bitmapfactory.options options = new bitmapfactory.options(); options.insamplesize = 8; bitmap bitmap = bitmapfactory.decodefile(filepath,options); rect rect = new rect(0, 0, bitmap.getwidth(), bitmap.getheight()); canvas.drawbitmap(bitmap, null, rect,null); }
}
main1.xml
<?xml version="1.0" encoding="utf-8"?><relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <com.hasse.move.drawview android:id="@+id/mainview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignparenttop="true" android:background="#00ff00" android:adjustviewbounds="true" /> <relativelayout android:id="@+id/innerrelativelayout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" > <edittext android:id="@+id/edittextaddtext" android:layout_width="fill_parent" android:layout_toleftof="@+id/btnsave" android:layout_height="wrap_content" android:text="wrap" /> <button android:id="@+id/btnsave" android:layout_alignparentright="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="save" /> </relativelayout> </relativelayout>
main activity
public class main extends activity { drawview theimage; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); // draw view setcontentview(r.layout.main1); theimage = (drawview) findviewbyid(r.id.mainview); //do stuff } @override public void onconfigurationchanged(configuration newconfig) { // toast.maketext(this, "onconfigurationchanged",toast.length_long).show(); super.onconfigurationchanged(newconfig); } }
here using destination rectangle size of loaded bitmap instead of full size of canvas: rect rect = new rect(0, 0, bitmap.getwidth(), bitmap.getheight());
you need find out size of canvas. can use onsizechanged:
@override public void onsizechanged (int w, int h, int oldw, int oldh){ super.onsizechanged(w, h, oldw, oldh); screenw = w; screenh = h; }
Comments
Post a Comment