This example describes the ImageView usage of the Android control. Share to everyone for your reference. Specifically as follows:
The ImageView control is a picture control that is responsible for displaying pictures.
The following analog mobile phone picture viewer
Directory structure:
Main.xml Layout file:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "android:orientation=" vertical "android:layout_width=" fill_parent "android:layout_height=" Fill_parent " > <imageview android:id= "@+id/imageview" android:layout_width= wrap_content "android:layout_height=" Wrap_ Content "android:layout_gravity=" Center_horizontal "android:src=" @drawable/p1 "/> <linearlayout xmlns:android = "Http://schemas.android.com/apk/res/android" android:orientation= "horizontal" android:layout_width= "fill_parent "Android:layout_height=" wrap_content "android:layout_gravity=" Center_horizontal "> <button android:id=" @+id/ Previous "android:layout_width=" Wrap_content "android:layout_height=" Wrap_content "android:text=" Last "Android: layout_gravity= "Center_horizontal"/> <button android:id= "@+id/alpha_plus" android:layout_width= Content "android:layout_height=" wrap_content "android:text=" transparencyAdd "android:layout_gravity=" Center_horizontal "/> <button android:id=" @+id/alpha_minus "android:layout_width=" "Wrap_content" "android:layout_height=" wrap_content "android:text=" Transparency reduction "android:layout_gravity=" Center_horizonta
L "/> <button android:id=" @+id/next "android:layout_width=" wrap_content "android:layout_height=" Wrap_content " Android:text= "Next" android:layout_gravity= "Center_horizontal"/> </LinearLayout> </LinearLayout>
Imageviewactivity class:
Package COM.LJQ.IV;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.Button;
Import Android.widget.ImageView;
public class Imageviewactivity extends activity {private ImageView imageview=null; Private button previous=null;//A private button next=null;//the next private button alpha_plus=null;//transparency increase private button alpha_minus=null;//Transparency Reduction private int currentimgid=0;//record current imageview display picture ID private int alpha=255;//record ImageView transparency in t [] Imgid = {//imageview displays an array of pictures R.DRAWABLE.P1, R.DRAWABLE.P2, R.drawable.p3, R.DRAWABLE.P4, r.drawable
. P5, R.drawable.p6, R.DRAWABLE.P7, R.DRAWABLE.P8,};
@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
imageview= (ImageView) Findviewbyid (R.id.imageview);
Previous= (Button) Findviewbyid (r.id.previous);
next= (Button) Findviewbyid (R.id.next); Alpha_plus= (Button) Findviewbyid (r.id.alpha_pLUs);
Alpha_minus= (Button) Findviewbyid (R.id.alpha_minus);
Previous.setonclicklistener (listener);
Next.setonclicklistener (listener);
Alpha_plus.setonclicklistener (listener);
Alpha_minus.setonclicklistener (listener);
Private View.onclicklistener listener = new View.onclicklistener () {public void OnClick (View v) {if (v==previous) {
Currentimgid= (currentimgid-1+imgid.length)%imgid.length;
Imageview.setimageresource (Imgid[currentimgid]);
} if (V==next) {currentimgid= (currentimgid+1)%imgid.length;
Imageview.setimageresource (Imgid[currentimgid]);
} if (V==alpha_plus) {alpha+=10;
if (alpha>255) {alpha=255;
} imageview.setalpha (Alpha);
} if (V==alpha_minus) {alpha-=10;
if (alpha<0) {alpha=0;
} imageview.setalpha (Alpha);
}
}
}; }
Run Result:
I hope this article will help you with your Android program.