android 底部导航栏中间图片,android底部菜单栏的实现和百度地图API的使用

本例子的代码清单:

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 p_w_picpath 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目录下,如图:

f00277c991d4bf1977dd493f7ab4fbde.png

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

a7faa31cc1ff8441a395e96827730958.png

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用Android的BottomNavigationView来创建底部导航栏。要创建凸起的效果,你需要使用一个自定义布局来替换默认的菜单项。以下是一些步骤: 1. 创建一个自定义布局,例如一个带有凸起图标的ImageButton。 2. 在布局中设置你的图标并添加点击事件。 3. 在你的Activity中,使用setContentView()方法将你的自定义布局设置为底部导航栏的视图。 4. 使用setOnNavigationItemSelectedListener()方法来处理导航栏项的选中事件。 这是一个示例代码: ``` // 创建自定义布局 View customView = LayoutInflater.from(this).inflate(R.layout.custom_layout, null); ImageButton customButton = customView.findViewById(R.id.custom_button); // 设置导航栏视图 BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation); bottomNavigationView.addView(customView); // 处理导航栏项的选中事件 bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.menu_item1: // 处理点击事件 return true; case R.id.menu_item2: // 处理点击事件 return true; case R.id.menu_item3: // 处理点击事件 return true; case R.id.custom_button: // 处理点击事件 return true; default: return false; } } }); ``` 请注意,你需要在自定义布局中为ImageButton添加一个唯一的ID,并在setOnNavigationItemSelectedListener()方法中使用它来处理点击事件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值