The project needs to use in the code to dynamically adjust the position of the picture and set the size of the picture, can automatically zoom the picture, with the ImageView control, as follows:
1. layout file
<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context= "${relativepackage}.${activityclass}" > <ImageViewAndroid:id= "@+id/image01"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:scaletype= "Fitxy"android:src= "@drawable/aabb" /></Relativelayout>
2. Java code
public class Mainactivity extends Activity {private ImageView image; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); image = (ImageView ) Findviewbyid (R.ID.IMAGE01); Set the position of the picture marginlayoutparams Margin9 = new Marginlayoutparams (Image.getlayoutparams ()); Margin9.setmargins (400, 10, 0, 0)///on the left margin 400 pixels, the top margin 10 pixels position display Picture relativelayout.layoutparams LayoutParams9 = new Relativelayout.layoutparams (MARGIN9); Layoutparams9.height = 600;//Sets the height of the picture layoutparams9.width = 800; Sets the width of the picture image.setlayoutparams (LAYOUTPARAMS9);}}
3. Effect
Dynamically set the size of the picture in Android code (auto-scale), position