StackView堆视图实现叠放效果

效果图:

StackView堆视图实现叠放效果_第1张图片

布局代码:

<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);
    }

}

你可能感兴趣的:(stackview,叠,堆视图)