类概述 在二维滚动网格中显示条目的视图.网格中的条目来自与视图关联的 ListAdapter. XML属性
实例 布局文件 <?xml version="1.0" encoding="utf-8"?><GridViewxmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:columnWidth="90dp" android:numColumns="auto_fit" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:stretchMode="columnWidth" android:gravity="center" /> mainActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); GridView gridview = (GridView) findViewById(R.id.gridview); gridview.setAdapter(new ImageAdapter(this)); gridview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Toast.makeText(HelloGridView.this, "" + position, Toast.LENGTH_SHORT).show(); } }); } ImageAdapter 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 }; } 代码量很小,我就不上传程序了!给大家分享一个我在网上找的GridView和ListView的上拉加载,下拉刷新的例子吧(个人感觉很实用)! 又放不下了!郁闷中...... 详见的表格都在 史上最全系列之用户界面之gridview二 里了! |
效果图
ConstConstantant |
Value |
DescDescriptionription |
top |
0x30 |
将对象放在其容器的顶部,不改变其大小. |
bottom |
0x50 |
将对象放在其容器的底部,不改变其大小. |
left |
0x03 |
将对象放在其容器的左侧,不改变其大小. |
right |
0x05 |
将对象放在其容器的右侧,不改变其大小. |
center_vertical |
0x10 |
将对象纵向居中,不改变其大小. |
fill_vertical |
0x70 |
必要的时候增加对象的纵向大小,以完全充满其容器. |
center_horizontal |
0x01 |
将对象横向居中,不改变其大小. |
fill_horizontal |
0x07 |
必要的时候增加对象的横向大小,以完全充满其容器. |
center |
0x11 |
将对象横纵居中,不改变其大小. |
fill |
0x77 |
必要的时候增加对象的横纵向大小,以完全充满其容器. |
clip_vertical |
0x80 |
附加选项,用于按照容器的边来剪切对象的顶部和/或底部的内容.剪切基于其纵向对齐设置:顶部对齐时,剪切底部;底部对齐时剪切顶部;除此之外剪切顶部和底部. |
clip_horizontal |
0x08 |
附加选项,用于按照容器的边来剪切对象的左侧和/或右侧的内容.剪切基于其横向对齐设置:左侧对齐时,剪切右侧;右侧对齐时剪切左侧;除此之外剪切左侧和右侧. |
start |
0x00800003 |
将对象置于容器的开始处,不改变其大小. |
end |
0x00800005 |
将对象置于容器的结尾处,不改变其大小. |
ConConstantstant |
ValValueue |
DescrDescriptioniption |
auto_fit |
-1 |
显示尽可能多的列,以填充所有空白. |
ConstantConstant | ValValue | DescriptionDescription |
none | 0 | 不伸缩. |
spacingWidth | 1 | 伸缩各列间的空白. |
columnWidth | 2 | 各列伸缩为等宽. |
spacingWidthUniform | 3 | 各列空白均匀伸缩. |
史上最全系列之用户界面之gridview一,布布扣,bubuko.com
原文:http://www.cnblogs.com/zhanganju/p/3683983.html