This article illustrates the simple application of Android programming imitation iphone drag photo effects gallery. Share to everyone for your reference, specific as follows:
Step 1: prepare the picture material.
Will icon2,icon3,icon4,icon5,icon6 five pictures into the res/drawable plus icon.png itself a total of 6 pictures.
Step 2: new Android project, named Gallerydemo.
Step 3: Design the UI and modify the Main.xml code as follows:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/" Apk/res/android "
android:background=" @drawable/white "
android:orientation=" vertical "
android: Layout_width= "Fill_parent"
android:layout_height= "fill_parent"
>
<textview android:id=
"@ +id/mytextview01 "
android:layout_width=" fill_parent "
android:layout_height=" Wrap_content
" android:text= "@string/hello"
android:gravity= "center_vertical|center_horizontal"
/>
< Gallery
android:id= "@+id/mygallery1"
android:layout_width= "Fill_parent"
Wrap_content "
android:gravity=" bottom "
/>
</LinearLayout>
Step 4: Design the main program class Gallerydemo.java code as follows:
Package com.android.test;
Import com.android.test.r.drawable;
Import android.app.Activity;
Import Android.content.Context;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.BaseAdapter;
Import Android.widget.Gallery;
Import Android.widget.ImageView; The public class Gallerydemo extends activity {/** called the ' when the ' is the ' The activity ' is a./@Override public void created
Reate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
((Gallery) Findviewbyid (R.id.mygallery1)). Setadapter (New Imageadapter (this));
The public class Imageadapter extends Baseadapter {/* class member Mycontext for context parent class/private context mycontext; /* Use res/drawable Picture as the source of the picture/private int[] Myimageids = {Drawable.icon, drawable.icon2, Drawable.icon3, Drawable.icon4
, Drawable.icon5, drawable.icon6};
/* The constructor has only one parameter, that is, the context/public imageadapter to store (context c) {this.mycontext = C; /* * Returns the total number of all defined pictures * * public int GetCount () {return this.myImageIds.length;
/* Use the GetItem method to obtain the array ID of the image in the current container/public Object getitem (int position) {return position;
public long getitemid (int position) {return position; /* * Get the image view currently to be displayed, and pass the array ID value to read and imaging/public View GetView (int position, View Convertview, ViewGroup parent) {/* Create an I
Mageview Object * * ImageView i = new ImageView (this.mycontext);
I.setimageresource (This.myimageids[position]);
I.setscaletype (ImageView.ScaleType.FIT_XY);
/* Set the width of the ImageView object, the unit is dip * * I.SETLAYOUTPARAMS (new Gallery.layoutparams (120, 120));
return i; }/* Use the Getscale to return the views size (0.0f to 1.0f)/public float Getscale (boolean focused, int offset) {/* Formula according to the amount of displacement from the center:
1/(2 ^ offset) */return Math.max (0, 1.0f/(float) Math.pow (2, Math.Abs (offset));
}
}
}
Step 5:run it, the effect of the following figure:
Note: This code basic reference to the Android SDK Development example code Encyclopedia
For more information on Android-related content readers can view the site: "Android graphics and image processing skills summary", "Android Development introduction and Advanced Course", "Android debugging techniques and common problems solution summary", " Android Multimedia How-to Summary (audio, video, audio, etc), summary of Android Basic components usage, Android View tips Summary, Android layout layout tips and a summary of Android controls usage
I hope this article will help you with the Android program.