Android基础篇之底部菜单栏的编辑
来源:互联网 发布:中国人歧视中国人知乎 编辑:程序博客网 时间:2024/05/16 07:23
先看效果图: 如下
下面是代码部分:
1. 在main.xml中添加GridView
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:background="@drawable/background"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <GridView
- android:id="@+id/grid_view"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:numColumns="5"
- android:horizontalSpacing="10dp"
- android:verticalSpacing="10dp">
- </GridView>
- </RelativeLayout>
2.注意:菜单栏中的每一子项都需要一个布局文件
如上图 是一个垂直布局的LinearLayout
menu_item.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <ImageView
- android:id="@+id/item_iamge"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal"
- />
- <TextView
- android:id="@+id/item_text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal"/>
- </LinearLayout>
3.主要代码部分 MainActivity.java
- package com.yin.bottom_menu;
- import java.util.ArrayList;
- import java.util.HashMap;
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.GridView;
- import android.widget.SimpleAdapter;
- public class MainActivity extends Activity {
- //图片资源
- private static int[] images = {
- R.drawable.menu_add_new,
- R.drawable.menu_delete,
- R.drawable.menu_exit,
- R.drawable.menu_search,
- R.drawable.menu__list
- };
- //菜单栏中的文字显示
- private static String[] menu_texts = {
- "增加","删除","退出","查找","菜单"
- };
- private ArrayList<HashMap<String,Object>> menu_data ;
- private GridView grid_view;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- init_menu();
- }
- //初始化底部菜单栏
- private void init_menu(){
- grid_view = (GridView) findViewById(R.id.grid_view);
- add_menu_data();
- //向菜单栏中的控件添加适配其
- SimpleAdapter adapter = new SimpleAdapter(this, menu_data, R.layout.menu_item,
- new String[]{"menu_image","menu_text"}, new int[]{R.id.item_iamge,R.id.item_text});
- grid_view.setAdapter(adapter);
- }
- //添加菜单栏中显示的数据
- private void add_menu_data(){
- menu_data = new ArrayList<HashMap<String,Object>>();
- for(int i=0;i<images.length;i++){
- HashMap<String,Object> map = new HashMap<String, Object>();
- map.put("menu_image", images[i]);
- map.put("menu_text", menu_texts[i]);
- menu_data.add(map);
- }
- }
- }
0 0
- Android基础篇之底部菜单栏的编辑
- Android基础篇之底部菜单栏的编辑
- android 隐藏底部的 菜单栏
- android实现底部菜单栏
- android实现底部菜单栏
- Android底部菜单栏设计
- android底部菜单栏demo
- android底部菜单栏实现
- android底部菜单栏
- Android底部菜单栏
- Android--底部菜单栏实现
- android底部菜单栏demo
- android底部菜单栏demo .
- Android底部菜单栏
- Android 底部菜单栏实现
- android实现底部菜单栏
- Android创建底部菜单栏
- Android自定义View之实现流行的底部菜单栏中间突起:高仿“咸鱼APP”的底部菜单。
- java实现排列组合实现
- 谷歌搜索技巧
- js刷新页面方法大全
- 使用两个队列实现一个栈
- 渗透学习笔记之密码相关
- Android基础篇之底部菜单栏的编辑
- 工作流Activiti的学习总结(一)安装条件以及各步骤的作用以及不同环境需要lib包
- 面向对象 构造代码块 静态代码块
- 别样JAVA学习(五)继承上(0.0)继承概述
- linux设备驱动——UVC驱动程序
- BZOJ 1014 JSOI 2008 火星人prefix Splay维护字符串Hash + 二分
- Spring管理quartz动态创建定时器,增,删,改,查
- python-变量的作用域
- 使用AutoHotkey在当前目录打开命令行(cmd.exe)