Android StackView 使用示例

cell.xml 布局文件:



主布局文件:




    

    

主程序代码:

package com.toby.personal.testlistview;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.SimpleAdapter;
import android.widget.StackView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends Activity {

    final private static String TAG = "Toby_Test";

    private StackView stackView = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final int[] images = new int[]{
                R.drawable.img01, R.drawable.img02, R.drawable.img03, R.drawable.img04,
                R.drawable.img05, R.drawable.img06, R.drawable.img07, R.drawable.img08,
                R.drawable.img09, R.drawable.img10, R.drawable.img11, R.drawable.img12,
                R.drawable.dog_001, R.drawable.dog_002, R.drawable.dog_003, R.drawable.dog_004,
                R.drawable.dog_005,
                R.drawable.girl01, R.drawable.girl02, R.drawable.girl03, R.drawable.girl04,
                R.drawable.girl05
        };

        List> listItems = new ArrayList<>();

        for (int i = 0; i < images.length; ++i) {
            Map listItem = new HashMap<>();
            listItem.put("image", images[i]);
            listItems.add(listItem);
        }

        SimpleAdapter simpleAdapter = new SimpleAdapter(this, listItems, R.layout.cell,
                new String[] {"image"}, new int[] {R.id.cellImage});

        stackView = (StackView) findViewById(R.id.stackView);
        stackView.setAdapter(simpleAdapter);
    }


    public void prev(View view) {
        stackView.showPrevious();
    }

    public void next(View view) {
        stackView.showNext();
    }

}

运行效果:


Android StackView 使用示例_第1张图片
运行效果

参考文献:《疯狂Android讲义(第2版)》

你可能感兴趣的:(Android StackView 使用示例)