Android - Grid View
2015-12-06 20:27
274 查看
》
displays items in a two-dimensional, scrollable grid. The grid items are automatically inserted to the layout using a
GridViewis a
ViewGroupthat
displays items in a two-dimensional, scrollable grid. The grid items are automatically inserted to the layout using a
ListAdapter.
<?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridview" android:layout_width="match_parent" android:layout_height="match_parent" android:columnWidth="90dp" android:numColumns="auto_fit" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:stretchMode="columnWidth" android:gravity="center" />
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 }; }
相关文章推荐
- Android中View 绘制机制
- Android中HandlerThread和IntentService详解
- 使用large 限定符 最小宽度限定符
- 有焦点的TextView
- 基于Android应用《玩转英语》(总报告)
- Android -- List View
- Android Studio 的所有常用快捷键
- PullToRefreshLibrary设置label提示信息注意点
- Android中Acition和Category常量表
- Android开发学习之路-自定义ListView(继承BaseAdapter)
- Android Default Settings
- 至Android虚拟机发送短信和拨打电话
- 读《50 Android Hacks》笔记整理Hack 24~Hack 30
- android中的category
- Android开发之Intent.Action
- 【Android】ImageView按下后的滤镜效果示例
- Android中选项菜单optionsMenu的创建及使用---onCreateOptionsMenu()等
- 【Android】MD5加密工具
- 43.Android Base64Util
- Android 数据库SQL增、删、查、改