安卓学习第19课——StackView

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:orientation="horizontal">

    <StackView
        android:id="@+id/stackView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:loopViews="true"/>
   <LinearLayout 
           android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:orientation="horizontal">

       <Button
           android:id="@+id/button1"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="上一个" 
           android:onClick="prev"/>

       <Button
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="下一个" 
           android:onClick="next"/>

</LinearLayout>
    

</LinearLayout>
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal"
    android:padding="2pt"
    >
<ImageView
    android:id="@+id/image1"
    android:layout_width="120dp" 
    android:layout_height="120dp" 
    />    
</LinearLayout>
package com.example.stackview;

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

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

public class MainActivity extends Activity {

    int[] imageIds=new int[]{
            R.drawable.shuangzi,R.drawable.shuangyu,R.drawable.chunv,
            R.drawable.tiancheng,R.drawable.tianxie,R.drawable.sheshou,R.drawable.juxie,
            R.drawable.shuiping,R.drawable.shizi,R.drawable.baiyang,R.drawable.jinniu,R.drawable.mojie
        };
    StackView stackView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        stackView=(StackView) findViewById(R.id.stackView);
        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 adapter=new SimpleAdapter(this,
                listItems, R.layout.cell,new String[]{"image"}, new int[]{R.id.image1});
        stackView.setAdapter(adapter);
    }
    public void prev(View source){
        stackView.showPrevious();
    }
    public void next(View source){
        stackView.showNext();
    }
}

功能和上一课的差不多,代码同样很容易理解。

转载于:https://www.cnblogs.com/Yvettey-me/p/3933306.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值