码迷,mamicode.com
首页 > 其他好文 > 详细

StackView堆视图实现叠放效果

时间:2015-08-04 11:17:14      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:stackview      堆视图   

效果图:

技术分享

布局代码:

<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堆视图实现叠放效果

标签:stackview      堆视图   

原文地址:http://blog.csdn.net/pengkv/article/details/47272811

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!