效果图:
布局代码:
<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);
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-19 00:45:35