進階控制項【安卓6】—— Gallery

來源:互聯網
上載者:User

標籤:對齊   技術分享   out   border   isp   dap   spi   data   列表   

 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代碼

 

進階控制項【安卓6】—— Gallery

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.