android底部固定菜单栏的实现(一),android底部菜单栏的实现和百度地图API的使用...

本文介绍了如何在Android应用中实现底部菜单栏,包括使用TextView组件绘制按钮并设置点击事件。同时,讲解了如何集成和使用百度地图API,包括引入相关jar包和在BaiduMap.java文件中的基本使用方法。
摘要由CSDN通过智能技术生成

本例子的代码清单:

FirstActivity.java : 模拟应用程序启动时的全屏载入效果;

SecondActivity.java : 程序主界面,实现底部菜单栏;

BaiduMap.java : 百度地图API的调用例子。

一、底部菜单栏的实现:

在SecondActivity.java中调用两个函数,onDrawBottomMenu()和setOnBottomMenuTouchListener()函数,前者用于绘制底部菜单栏,后者实现按钮的点击响应事件。

在onDrawBottomMenu()函数中,

private void onDrawBottomMenu()

{

//get the resource of each button

Start = (TextView)findViewById(R.id.training);

History = (TextView)findViewById(R.id.history);

Weibo = (TextView)findViewById(R.id.weibo);

Location = (TextView)findViewById(R.id.myLocation);

//set the back ground image of each button

//Start.setBackgroundResource(R.drawable.start);

Start.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.start), null, null);

History.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.history), null, null);

Weibo.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.weibo), null, null);

Location.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.location), null, null);

Start.setTextSize(16);

History.setTextSize(16);

Weibo.setTextSize(16);

Location.setTextSize(16);

}

如 line4~line7,使用的是TextView组件实现菜单栏的按钮。通过setCompoundDrawablesWithIntrisicBounds()方法绘制按钮背景图,该函数还很方便各组件之间设置相对位置。

布局文件:

xmlns:android="http://schemas.android.com/apk/res/android"

android:background="@drawable/menu_background"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

>

android:id="@+id/training"

android:text="@string/startTraining"

android:gravity="center_horizontal"

android:layout_alignParentLeft="true"

android:layout_width="80dip"

android:layout_height="wrap_content"

>

android:id="@+id/history"

android:text="@string/historyRecord"

android:gravity="center_horizontal"

android:layout_toRightOf="@id/training"

android:layout_width="80dip"

android:layout_height="wrap_content"

>

android:id="@+id/weibo"

android:text="@string/weibo"

android:gravity="center_horizontal"

android:layout_toRightOf="@id/history"

android:layout_width="80dip"

android:layout_height="wrap_content"

>

android:id="@+id/myLocation"

android:text="@string/myLocation"

android:gravity="center_horizontal"

android:layout_toRightOf="@id/weibo"

android:layout_width="80dip"

android:layout_height="wrap_content"

>

二、百度地图API的使用

先到百度地图API首页下载相关的jar包,http://developer.baidu.com/map/,在“开发资源”中找到要下载的资源。

将相关的jar文件复制到lib目录下,如图:

0818b9ca8b590ca3270a3433284dd417.png

将jar库加入到工程中,单击项目名称,右键―>Properties―>Java Build Path―>Libraries―>Add JARs,将baidumapapi_v2_1_2.jar文件添加到工程中。如图:

0818b9ca8b590ca3270a3433284dd417.png

API的使用在BaiduMap.java文件中,有兴趣的读者可以下载看看。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值