主要的activity
public class MainActivity extends Activity {
private Button pre;
private Button next;
private StackView stackView;;
private int[] imageIds = { R.drawable.fy_d_go, R.drawable.fy_d_kf,
R.drawable.fy_d_kf2, R.drawable.fy_d_kf_s, R.drawable.fy_d_more_s,
R.drawable.ic_launcher };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pre = (Button) findViewById(R.id.button1);
next = (Button) findViewById(R.id.button2);
stackView = (StackView) findViewById(R.id.stackView1);
List<Map<String, Object>> listItems = new ArrayList<Map<String,Object>>();
for(int i=0;i<imageIds.length;i++){
Map<String, Object> listItem = new HashMap<String, Object>();
listItem.put("image", imageIds[i]);
listItems.add(listItem);
}
SimpleAdapter adapter = new SimpleAdapter(this, listItems, R.layout.textview, new String[]{"image"}, new int[]{R.id.imageview3});
stackView.setAdapter(adapter);
pre.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
stackView.showPrevious();
}
});
next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
stackView.showNext();
}
});
}
}
布局文件xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
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=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="上一个" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:text="下一个" />
<StackView
android:id="@+id/stackView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button2"
android:layout_marginTop="74dp" >
</StackView>
</RelativeLayout>