-4
A
回答
0
上面的示例是一個gridView,其中顯示了一些圖片(mThumbIds)。
通過xml創建一個gridView。
然後把它在你的代碼是這樣的:
GridView gv = (GridView) findViewById(R.id.gridView1);
然後創建一個圖像適配器,並將其連接到您的的GridView:
imageAdapter = new ImageAdapter(this);
gv.setAdapter(imageAdapter);
這裏代碼爲您的ImageAdapter:
對網格中的每個項目執行getView方法。
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7
};
}
相關問題
- 1. Android上的網格佈局?
- 2. 的Android V7網格佈局
- 3. android網格佈局大小
- 4. 網格佈局
- 5. 網格佈局
- 6. XAML網格佈局
- 7. Wpf網格佈局
- 8. HTML5網格佈局
- 9. XAML網格佈局
- 10. 鈦,網格佈局
- 11. HTML網格佈局
- 12. 網格佈局Java
- 13. CSS網格佈局
- 14. Android:在網格佈局中滾動?
- 15. 覆蓋佈局在網格上的Android
- 16. Android XML佈局對齊(按鈕網格)
- 17. 的Android什麼網格佈局使用
- 18. Android查看位於網格佈局
- 19. Android相對佈局網格按鈕
- 20. 的GridView VS網格佈局Android應用
- 21. Android Studio,網格佈局絕不相同
- 22. Android Studio網格佈局刷新
- 23. Android的網格佈局columnSpan不跨越
- 24. Android的網格佈局四溢屏幕
- 25. 的Android網格佈局顯示
- 26. Android/XML佈局,按鈕的網格
- 27. Android的網格佈局不顯示
- 28. Android:佈局重量在網格佈局中不起作用
- 29. Android:如何在線性佈局內設置網格佈局?
- 30. 哪種佈局網格佈局或TableLayout適用於Android的
嘗試這裏http://developer.android.com/guide/topics/ui/layout/gridview.html – GhostDerfel
我想用網格佈局 – user3244162
也許這個例子可以幫助你:HTTP://博客.stylingandroid.com/archives/669 http://www.techotopia.com/index.php/Working_with_the_Android_GridLayout_in_XML_Layout_Resources – GhostDerfel