跟着郑平老师做通讯录小项目时学到布局界面底部的控件

本文详细介绍了如何利用SiampleAdapter在Android应用中创建一个高效的GridView,包括布局设计、数据填充及样式调整等关键步骤。通过实践操作,读者能够掌握将图像与文本结合展示的方法,提升用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

界面底部整体是一个GirdView 一行一共五列,每一项是上面图片下面是Text 用SiampleAdapter进行加入 GirdView中每一项的布局如下: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingBottom="5dip" > <ImageView android:id="@+id/item_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" /> <TextView android:id="@+id/item_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/item_image" android:layout_centerHorizontal="true" /> </RelativeLayout>

Java代码如下:package com.jiangqq; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.Activity; import android.os.Bundle; import android.view.Gravity; import android.widget.GridView; import android.widget.SimpleAdapter; public class GirdViewActivity extends Activity { private GridView gv_button_menu; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); loadButtonMenu(); } private void loadButtonMenu() { gv_button_menu = (GridView) this.findViewById(R.id.gv_buttom_menu); gv_button_menu.setBackgroundResource(R.drawable.channelgallery_bg); // 设置每行的列数 gv_button_menu.setNumColumns(5); gv_button_menu.setGravity(Gravity.CENTER); gv_button_menu.setVerticalSpacing(10); gv_button_menu.setHorizontalSpacing(10); List data = new ArrayList(); Map map = new HashMap(); map.put("itemImage", R.drawable.menu_new_user); map.put("itemText", "添加"); data.add(map); map = new HashMap(); map.put("itemImage", R.drawable.menu_search); map.put("itemText", "查找"); data.add(map); map = new HashMap(); map.put("itemImage", R.drawable.menu_delete); map.put("itemText", "删除"); data.add(map); map = new HashMap(); map.put("itemImage", R.drawable.controlbar_showtype_list); map.put("itemText", "菜单"); data.add(map); map = new HashMap(); map.put("itemImage", R.drawable.menu_exit); map.put("itemText", "退出"); data.add(map); SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.item_menu, new String[] { "itemImage", "itemText", }, new int[] { R.id.item_image, R.id.item_text }); gv_button_menu.setAdapter(adapter); } } 最后说一下 郑平老师讲的也不错,这两天连续做了三个小项目,也学到了很多东西,要好总结一下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值