<LinearLayoutxmlns: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"android:orientation= "Horizontal"> <StackViewAndroid:id= "@+id/stackview"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:loopviews= "true"/> <LinearLayoutAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:orientation= "Horizontal"> <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Previous"Android:onclick= "Prev"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Next"Android:onclick= "Next"/></LinearLayout> </LinearLayout>
<?XML version= "1.0" encoding= "UTF-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "Horizontal"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:gravity= "Center_horizontal"android:padding= "2pt" ><ImageViewAndroid:id= "@+id/image1"Android:layout_width= "120DP"Android:layout_height= "120DP" /> </LinearLayout>
PackageCom.example.stackview;Importjava.util.ArrayList;ImportJava.util.HashMap;Importjava.util.List;ImportJava.util.Map;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.SimpleAdapter;ImportAndroid.widget.StackView; Public classMainactivityextendsActivity {int[] imageids=New int[]{R.DRAWABLE.SHUANGZI,R.DRAWABLE.SHUANGYU,R.DRAWABLE.CHUNV, R.drawable.tiancheng,r.drawable.ti Anxie,r.drawable.sheshou,r.drawable.juxie, R.DRAWABLE.SHUIPING,R.DRAWABLE.SHIZI,R.DRAWABLE.BAIYANG,R.DRAWABLE.J Inniu,r.drawable.mojie}; StackView StackView; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); StackView=(StackView) Findviewbyid (R.id.stackview); List<Map<String,Object>> listitems=NewArraylist<map<string, object>>(); for(inti=0;i<imageids.length;i++) {Map<String,Object> listitem=NewHashmap<string, object>(); Listitem.put ("Image", Imageids[i]); Listitems.add (ListItem); } Simpleadapter Adapter=NewSimpleadapter ( This, ListItems, R.layout.cell,Newstring[]{"Image"},New int[]{r.id.image1}]; Stackview.setadapter (adapter); } Public voidprev (View source) {stackview.showprevious (); } Public voidNext (View source) {Stackview.shownext (); }}
The function is similar to the previous lesson, and the code is easy to understand.
Android 18th Lesson--stackview