標籤:對齊 技術分享 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