Android(安卓)GridView 方格中图标与文字如何同时存在
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;
}
更多相关文章
- Android(安卓)RecyclerView控件
- 个人经验 - Android的RelativeLayout布局的layout_height属性设
- LayoutInflater那些事儿
- Android换肤Demo
- Android中自定义适配器的使用
- android mediaplayer概况
- 关于Android(安卓)7.0下Launcher3下default_workspace.xml修改无
- ScrollView中的控件占据ScrollView的match_parent
- android接收adb发送的系统广播及自定义广播