zoukankan      html  css  js  c++  java
  • 【安卓6】高级控件—— Gallery

     Gallery画廊

    Gallery控件与Spinner类相似,都是AbsSpinner类的子类。

    Spinner显示的是一个垂直列表选择,Gallery显示的是一个水平列表选择框,(允许用户水平拖动列表框)

    方法

    属性

    描述

    public Gallery(Context context)

    创建Gallery对象

    public void setSpacing(int spacing)

    android: spacing

    设置两个图片之间的显示间距

    public void setAdapter(

           SpinnerAdapter adapter)

    设置图片集

    public void setGravity(int gravity)

    android: gravity

    设置图片的对齐方式

    public void setOnItemClickListener(

        AdapterView.OnItemClickListener)

    设置选项单击事件

    Gallery ga=(Gallery) findViewById(R.id.gallery);
    // 读到png结尾的图片
    Field[] fields = R.drawable.class.getDeclaredFields();
    List<Map<String, Integer>> data = new ArrayList<Map<String, Integer>>();
    for (Field field : fields) {
        Map<String, Integer> map = new HashMap<String, Integer>();
        try {
            map.put("img", field.getInt(R.drawable.class));
            data.add(map);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.gallery,
           new String[] { "img" },new int[] { R.id.gaImg });
    ga.setAdapter(adapter);
    Gallery部分java代码
  • 相关阅读:
    Common Element in Two Sorted Sets
    Nearest Points on a Plane
    Influencer Finder
    Range of Intervals
    *Common characters
    自定义栈 和装箱,拆箱
    1.Vector(同步)和ArrayList(异步)异同
    STL中的迭代器的使用
    如何优化limit?
    mysql五大引擎之间的区别和优劣之分
  • 原文地址:https://www.cnblogs.com/leelee/p/6994633.html
Copyright © 2011-2022 走看看