<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<StackView
android:id="@+id/mStackView"
android:layout_width="200dp"
android:layout_height="200dp"
android:layerType="hardware"
android:loopViews="false" />
</LinearLayout>
public class StackViewActivity extends Activity {
StackView stackView;
int[] imageIds = new int[]{R.drawable.c1, R.drawable.c2, R.drawable.c3, R.drawable.c4};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stack);
stackView = (StackView) findViewById(R.id.mStackView);
//创建一个List对象,List对象的元素是Map
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
SimpleAdapter simpleAdapter = new SimpleAdapter(this, listItems, R.layout.item_stack_image, new String[]{"image"}, new int[]{R.id.iv_city});
stackView.setAdapter(simpleAdapter);
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/pengkv/article/details/47272811