美文网首页Android 成长笔记
Android StackView 使用示例

Android StackView 使用示例

作者: 赵者也 | 来源:发表于2017-03-18 15:37 被阅读143次

cell.xml 布局文件:

<?xml version="1.0" encoding="utf-8"?>
<ImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/cellImage"
    android:layout_width="200dp"
    android:layout_height="200dp"
    />

主布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:background="@color/colorGray"
    >

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

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="prev"
        android:text="@string/prev"
        />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="next"
        android:text="@string/next"
        />

</LinearLayout>

主程序代码:

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<Map<String, Object>> listItems = new ArrayList<>();

        for (int i = 0; i < images.length; ++i) {
            Map<String, Object> 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讲义(第2版)》

相关文章

  • Android StackView 使用示例

    cell.xml 布局文件: 主布局文件: 主程序代码: 运行效果: 参考文献:《疯狂Android讲义(第2版)》

  • StackView

    Android中StackView的使用Android StackView用法

  • 系统小组件

    Android Widget 小部件(四---完结) 使用ListView、GridView、StackView...

  • Not just<what's new in St

    文中示例的项目地址:github 主要记录一些与StoryBoard相关的东西.目录如下: - StackView...

  • StackView使用问题

    StackView隐藏其子视图时发生约束冲突StackView在隐藏它的子view时,会使子view高度约束为0 ...

  • WebView中的文件选择

    html示例 Android代码 参考:Android使用WebView加载网页选择文件上传[https://bl...

  • Android 弹出菜单示例(Android sample AP

    Android 弹出菜单示例# 这个示例展示如何使用PopupMenu来现实和一个弹出的菜单。 说明 这个示例展示...

  • 媒体查询

    使用JS判断设备类型(判断设备使用iOS还是Android系统)的示例,代码如下:

  • swift UIStackView 背景色 无效

    合理使用 stackview,可以减少constraint的使用。constraint太多,也会对view的维护造...

  • 使用adb命令获得Android手机分辨率

    使用如下命令获得Android手机屏幕分辨率 命令 输出示例: 增加筛选 输出示例 保存为脚本方便下次使用

网友评论

    本文标题:Android StackView 使用示例

    本文链接:https://www.haomeiwen.com/subject/bogunttx.html