StackView

StackView_第1张图片

content_main.xml布局


    
    
        


cell.xml布局



    



用SimpleAdapter将数据显示在布局上
package com.eson.stackview ;

import android.os.Bundle ;
import android.support.v7.app.AppCompatActivity ;
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 StackViewTest extends AppCompatActivity {

    int [] imageIds= new int []{
            R.drawable. img1, R.drawable. img2, R.drawable. img3, R.drawable. img4,
            R.drawable. img5 ,R.drawable. img6 ,R.drawable. img7 ,R.drawable. img8 ,
            R.drawable. img9 ,R.drawable. img10 ,R.drawable. img11 ,R.drawable. img12 ,
    } ;
    private StackView stackView ;

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

        stackView = (StackView) findViewById(R.id. mStackView );
        //创建一个List对象,List对象的元素是Map
        List> listItems= new ArrayList<>() ;
        for ( int i = 0 ; i < imageIds . length; i++) {
            Map listItem= new HashMap<>();
            listItem.put( "image" ,imageIds [i]) ;
            listItems.add(listItem) ;
        }
        //创建一个SimpleAdapter
        SimpleAdapter simpleAdapter = new SimpleAdapter(this, listItems , R.layout. cell , new String[]{ "image"} , new int []{R.id. image1}) ;
        stackView .setAdapter(simpleAdapter) ;

    }
    public void prev (View view){
        //显示上一个组件
        stackView .showPrevious() ;
    }
    public void next (View view){
        //显示下一个组件
        stackView .showNext() ;
    }
}

你可能感兴趣的:(StackView)