1, 先定义GridView方格中的元素布局

res/layout/appsviewcell.xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/appsviewcell_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ImageView
android:id="@+id/appsviewcell_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>

<TextView
android:id="@+id/appsviewcell_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_below="@+id/appsviewcell_image"/>
</RelativeLayout>

里面用到的一些参数在res/values/strings.xml中定义



关键部分:


@Override
public View getView(int position, View cellView, ViewGroup vgroup) {
// TODO Auto-generated method stub

AppsViewItemViewInfo itemViewInfo = null;
if(null == cellView)
{
cellView = this.mInflater.inflate(R.layout.appsviewcell, null);

ImageView iv = (ImageView)cellView.findViewById(R.id.appsviewcell_image);
TextView tv = (TextView)cellView.findViewById(R.id.appsviewcell_text);

AppsViewItemInfo appItemViewInfo = this.aviis[position];

iv.setImageResource(appItemViewInfo.getAppIcon());
String appname = appItemViewInfo.getAppName();
Log.d("DEBUG", "Position = "+position+", AppName = "+appname);
tv.setText(appname);

itemViewInfo = new AppsViewItemViewInfo();
itemViewInfo.setViewImage(iv);
itemViewInfo.setViewText(tv);

cellView.setTag(itemViewInfo);
}
else
{
itemViewInfo = (AppsViewItemViewInfo)cellView.getTag();
}

return cellView;
}




更多相关文章

  1. Android(安卓)RecyclerView控件
  2. 个人经验 - Android的RelativeLayout布局的layout_height属性设
  3. LayoutInflater那些事儿
  4. Android换肤Demo
  5. Android中自定义适配器的使用
  6. android mediaplayer概况
  7. 关于Android(安卓)7.0下Launcher3下default_workspace.xml修改无
  8. ScrollView中的控件占据ScrollView的match_parent
  9. android接收adb发送的系统广播及自定义广播

随机推荐

  1. Android消息处理两大利器:Handler and Loo
  2. Google Android真实的谎言
  3. 用Android搭建客户端 手机和服务器交互开
  4. android与pc的故事
  5. 工程师淘金:开发Android主攻四大方向
  6. Android(安卓)AsyncTask完全解析,带你从源
  7. Android线程模型解析(包括UI的更新)
  8. android 返回键与finish区别 onBackPress
  9. android 完美适配解决方案
  10. 王家林的81门一站式云计算分布式大数据&