Mainactivity.java:
Import Android.app.activity;import Android.graphics.bitmap;import Android.graphics.drawable.bitmapdrawable;import Android.os.bundle;import Android.view.menu;import Android.view.menuitem;import Android.view.MotionEvent;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.view.ontouchlistener;import Android.widget.button;import Android.widget.imageview;import Android.widget.linearlayout;public class MainActivity Extends activity {//define an array of access images int images[] = new int[] {r.drawable.yy00, r.drawable.yy01,r.drawable.yy02, R.drawable.yy03, r.drawable.yy04, R.drawable.yy05,r.drawable.yy06, R.drawable.yy07, R.DRAWABLE.YY08, R.drawable.yy09,r.drawable.yy11, R.drawable.yy12, r.drawable.yy13,};//defines the current picture int currentimage = 2;private int alpha = 255; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); final button plus = (button) Findviewbyid (r.id.plus); final button minus = (button) findViewbyid (R.id.minus); final ImageView ImageView = (ImageView) Findviewbyid (r.id.image1); final ImageView imageView2 = ( ImageView) Findviewbyid (r.id.image2); button next = (Button) Findviewbyid (R.id.next), Next.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (View v) {//TODO auto-generated method Stubimageview.setimageresource (images[++currentimage% images.length]);}); Onclicklistener listener = new Onclicklistener () {@Overridepublic void OnClick (View v) {//TODO auto-generated method stub if (v = = Plus) {alpha + = 20;} if (v = = minus) {alpha-= 20;} if (Alpha >= 255) {alpha = 255;} if (Alpha <= 0) {alpha = 0;} Imageview.setalpha (Alpha);}};/ /change Transparency Plus.setonclicklistener (listener); Minus.setonclicklistener (listener); Imageview.setontouchlistener (new Ontouchlistener () {@Overridepublic Boolean onTouch (View V, motionevent event) {//TODO auto-generated method stubbitmapdr Awable bitmapdrawable = (bitmapdrawable) imageview.getdrawable ();//Gets the bitmap in the first Picture display box bitmap bitmap = BITMAPDRawable.getbitmap ();//bitmap picture actual size with the first imageview scaling double scale = bitmap.getwidth ()/320.0;//Gets the start point of the picture that needs to be displayed int x = ( int) (EVENT.GETX () * scale), int y = (int) (event.gety () * scale), if (x + > Bitmap.getwidth ()) {x = Bitmap.getwidth ( )-120;} if (Y + > Bitmap.getheight ()) {y = Bitmap.getheight ()-120;} Displays the specified area of the picture Imageview2.setimagebitmap (Bitmap.createbitmap (Bitmap, X, y,120,)); Imageview2.setalpha (Alpha); return false;}});}}
Activity_main.xml:
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" fill_parent "android:layout_height=" Fill_parent "Android:orienta tion= "vertical" android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_ Horizontal_margin "android:paddingright=" @dimen/activity_horizontal_margin "android:paddingtop=" @dimen/activity_ Vertical_margin "tools:context=" com.example.imageviewdemo.MainActivity "> <linearlayout android:layout_ Width= "Fill_parent" android:layout_height= "wrap_content" android:gravity= "center" android:orientation = "Horizontal" > <button android:id= "@+id/plus" android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "increase transparency"/> <button android:id= "@+id/minus" android:layout_width= "wrap_content"Android:layout_height=" wrap_content "android:text=" reduce transparency "/> <button Andro Id:id= "@+id/next" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= "Next"/> </LinearLayout> <!--definition Show picture overall ImageView-<imageview android:i D= "@+id/image1" android:layout_width= "fill_parent" android:layout_height= "240px" android:scaletype= "f Itcenter "android:src=" @drawable/yy01 "/><!--definition show local picture ImageView--<imageview android:id=" @ +id/image2 "android:layout_width=" 120DP "android:layout_height=" 120DP "android:layout_margintop=" 10DP "Android:background=" #00f "/></linearlayout>
Android------ImageView