Android UI设计 屏幕底部的菜单栏 动画切换Activity

2023-11-11

最终效果如下图,点击菜单会切换Activity,有动画效果。

从早上起床就研究这个东西,因为之前一直都直接用系统提供的几个控件,从来没搞过图片背景、嵌套布局什么的,今天是第一次,没什么经验,花了一个上午才搞定。
简单介绍一下思路,使用LinearLayout嵌套,分三部分,第一部分是顶部的标题栏,第二部分是内容,第三部分是底部菜单。参考网上的代码,一路顺风顺水搞定,但在模拟器测试时出了问题(开发时用I9000),模拟器的屏幕是HVGA的,在上面运行看不到菜单栏。这个问题困扰了很久,网上也搜不出有用的答案(说是用dip,不用px,我开始就是用dip的),最后还是自己冥思苦想解决了问题,解决方法也很简单,就是让内容fill_parent,然后菜单layout_marginTop取个负值。
main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:gravity="clip_horizontal"
	android:layout_height="fill_parent" android:id="@+id/toplayout">
	<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
		android:orientation="horizontal" android:layout_width="fill_parent"
		android:layout_height="30dip" android:background="@drawable/header"
		android:gravity="center">
		<TextView android:layout_width="wrap_content"
			android:layout_height="wrap_content" android:id="@+id/toptv"
			android:gravity="center" android:textSize="20dip"
			android:layout_gravity="center" android:text="@string/home"/>
	</LinearLayout>
	<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
		android:orientation="vertical" android:layout_width="fill_parent"
		android:layout_height="fill_parent">
				<TextView android:layout_width="wrap_content"
			android:gravity="center" android:textSize="20dip"
			android:layout_gravity="center" android:text="@string/home" android:layout_height="fill_parent"/>
	</LinearLayout>
	<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
		android:orientation="vertical" android:layout_width="fill_parent" android:layout_marginTop="-50dip"
		android:layout_height="50dip" android:gravity="bottom" android:background="@drawable/header">
		<include layout="@layout/foot" />
	</LinearLayout>
</LinearLayout>

foot.xml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="horizontal" android:layout_width="fill_parent"
	android:layout_height="wrap_content">
	<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
		android:orientation="vertical" android:layout_width="80dip"
		android:layout_height="80dip" android:id="@+id/home"
		android:gravity="center_horizontal"
		>
		<TextView android:layout_width="wrap_content"
			android:layout_height="50dip"
			android:gravity="center" android:paddingTop="29dip"
			android:background="@drawable/tab_home"
			android:id="@+id/hometv"			
			 />
	</LinearLayout>
	<ImageView android:layout_width="wrap_content"
			android:layout_height="wrap_content"  android:src="@drawable/line" />
	<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
		android:orientation="vertical" android:layout_width="80dip"
		android:layout_height="wrap_content" android:gravity="center_horizontal"
		android:id="@+id/channel">
		<TextView android:layout_width="wrap_content"
			android:layout_height="50dip"
			android:gravity="center" android:paddingTop="29dip"
			 android:background="@drawable/tab_channel" android:id="@+id/channeltv" />
	</LinearLayout>
	<ImageView android:layout_width="wrap_content"
			android:layout_height="wrap_content"  android:src="@drawable/line" />
	<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
		android:orientation="vertical" android:layout_width="80dip" android:id="@+id/fav"
		android:layout_height="wrap_content" android:gravity="center_horizontal" >
		<TextView android:layout_width="wrap_content"
			android:layout_height="50dip"
			android:gravity="center" android:paddingTop="29dip"
			 android:background="@drawable/tab_fav" android:id="@+id/favtv" />
	</LinearLayout>
	<ImageView android:layout_width="wrap_content"
			android:layout_height="wrap_content"  android:src="@drawable/line" />
	<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
		android:orientation="vertical" android:layout_width="80dip" android:id="@+id/search"
		android:layout_height="wrap_content" android:gravity="center_horizontal">
		<TextView android:layout_width="wrap_content"
			android:layout_height="50dip"
			android:gravity="center" android:paddingTop="29dip"
			 android:background="@drawable/tab_search" android:id="@+id/searchtv"/>
	</LinearLayout>
</LinearLayout>

main.java:

package com.BottomMenu;
 
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.TextView;
 
public class main extends Activity {
	private LinearLayout home, channel, fav, search;
	TextView toptv;
 
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main);
		Init();
	}
	public void Init(){
        Animation anim = AnimationUtils.loadAnimation(this,R.anim.scale);
        findViewById(R.id.toplayout).startAnimation(anim);
        //这两行是启动activity的动画效果
		home = (LinearLayout) findViewById(R.id.home);
		TextView hometv=(TextView)home.findViewById(R.id.hometv);
		hometv.setBackgroundResource(R.drawable.tab_home_select);
		home.setBackgroundResource(R.drawable.tab_two_highlight);
		toptv=(TextView)findViewById(R.id.toptv);
 
		channel = (LinearLayout) findViewById(R.id.channel);
		channel.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent=new Intent();
				intent.setClass(main.this, channel.class);
				main.this.startActivity(intent);
			}
		});
 
		fav = (LinearLayout) findViewById(R.id.fav);
		fav.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent=new Intent();
				intent.setClass(main.this, fav.class);
				main.this.startActivity(intent);
			}
		});
 
		search = (LinearLayout) findViewById(R.id.search);
		search.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent=new Intent();
				intent.setClass(main.this, search.class);
				main.this.startActivity(intent);
			}
		});
	};
}

动画效果scale.xml:

1
2
3
4
5
6
7
8
9
10
11
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale android:interpolator="@android:anim/decelerate_interpolator"
        android:fromXScale="0.0" 
        android:toXScale="1.0" 
        android:fromYScale="0.0"
        android:toYScale="1.0" 
        android:pivotX="50%" 
        android:pivotY="50%"
        android:fillAfter="true" 
        android:duration="300" />
</set>

其他几个activity代码就不贴了,反正内容都一样,下面有代码打包供大家参考。 BottomMenu (275)

 

 

http://www.pocketdigi.com/20110225/186.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android UI设计 屏幕底部的菜单栏 动画切换Activity 的相关文章

  • Android 中用虚拟键盘捕捉按键按下的情况?

    使用物理键盘 您可以使用按键监听器 http developer android com reference android text method KeyListener html 就像是 myEditText setOnKeyListe
  • Android NDK 中使用“dynamic_cast”时出现“UnsatisfiedLinkError”

    我是 Android 开发新手 我面临下一个问题 当我使用 C 代码时 动态演员 表达方式 不满意的链接错误 当我在模拟器上启动应用程序时出现 但是当我在没有它的情况下运行应用程序时 一切正常 我的意思是 LogCat 没有任何错误 我尝试
  • 强制用户在 Android 中的 EditText 中输入内容

    我的活动中有几个编辑文本 我希望我的用户在提交表单之前正确输入 我该怎么做 我还有旋转器和 RadioGroup 按钮 你可以加验证在提交按钮上单击 private boolean validateFields int yourDesire
  • 安卓无法玩ogg

    有人知道这是什么意思吗 ogg使用phonegap is Media播放 它使用MediaPlayer 05 26 15 41 50 007 1160 3631 E AudioFlinger no more track names avai
  • 毕加索动画加载图像

    我有以下代码在毕加索中加载图像 使用可绘制的占位符在图像下载时显示 不过 我想要的是一个动画旋转进度条样式的旋转器 它可以在图像加载时不断地旋转 就像我在大多数专业应用程序中看到的那样 毕加索似乎不支持这一点 只支持静态图像可绘制 有没有办
  • 在 Android 中长按时从操作模式中删除后退/主页按钮

    我已经在里面长按实现了上下文操作模式recycler view 为此我打电话给ActionModeCallback从创建动作模式开始 创建动作模式时 默认显示后退箭头 检查如下 单击后退箭头 操作模式将关闭 现在我想要hide or rem
  • 如何从 Retrofit2 获取字符串响应?

    我正在做 android 正在寻找一种方法来执行超级基本的 http GET POST 请求 我不断收到错误 java lang IllegalArgumentException Unable to create converter for
  • 以编程方式更新 Android 中的联系人姓名和电话号码

    我创建一个应用程序来读取 更新 删除联系人详细信息 这是更新联系人姓名和电话号码的问题 有人可以帮助我吗 我该怎么做 我正在使用以下代码 但它不起作用 Override public View onCreateView LayoutInfl
  • 如何在android中设置多个闹钟,在这种情况下最后一个闹钟会覆盖以前的闹钟

    我正在开发一个Android应用程序 用户可以在其中设置提醒时间 但我在以下代码中遇到一个问题 即最后一个警报会覆盖之前的所有警报 MainActivity java public void setreminders DatabaseHan
  • 应用内结算错误

    我的 UNMANAGED 应用内购买无法正常工作 在它完美运行之前 我可以使用测试帐户成功购买 但它突然不起作用了 因为我记得我对商家帐户所做的只是添加更多 2 4 个测试帐户 添加后 我的应用内购买将不起作用 所以我更新了公钥并上传了一个
  • 尝试在模拟器上安装第二个 flutter 应用程序时出错

    我创建了一个简单的 flutter 应用程序并在 android 模拟器上运行它 效果还不错 现在我创建了另一个 当我尝试在模拟器上运行它时 我得到 Error ADB exited with exit code 1 adb failed
  • 如何强制从本机代码打开 Android 软键盘?

    我有一个游戏 当用户触摸屏幕时 它使用从 C 到 Java 的回调来强制打开软键盘 Java代码很简单是这样的 this inputMethodManager toggleSoftInput InputMethodManager SHOW
  • matlab 中的动画绘图

    我正在尝试创建一个三角形的动画图 最终结果应该是十个三角形 后面跟着两个更大的三角形 后面跟着一条直线 使用matlab文档 https de mathworks com help matlab ref drawnow html 我最终得到
  • 如何在进入新活动之前终止线程和处理程序

    大家好 在我尝试清理处理程序时 这段代码可能有点混乱 因为我一直在尝试追踪崩溃发生的位置 我有一个对话框活动 显示密码输入 进度条由线程和处理程序动画显示 似乎当我试图查看进度条是否完成并尝试终止线程时 当我尝试进入新活动时 我这样做的方式
  • 如何在 Android NDK 中创建新的 NativeWindow 而无需 Android 操作系统源代码?

    我想编译一个 Android OpenGL 控制台应用程序 您可以直接从控制台启动 Android x86 运行 或者从 Android x86 GUI 内的 Android 终端应用程序运行 这个帖子 如何在 Android NDK 中创
  • Vimeo 视频在 Android 6 设备上停止播放

    我正在尝试在我的应用程序中播放 Vimeo 的视频 问题是在 Android 6 设备上 视频会在一定时间后停止播放 在 API 较低的设备上一切正常 时间取决于质量 对于下面提供的网址的视频 播放一定分钟 1 到 3 视频质量有多低 播放
  • Android 从命令行停止模拟器

    这个问题与如何通过命令行关闭Android模拟器 https stackoverflow com questions 5912403 how to shut down android emulator via cmd 但是 在尝试第一个答案
  • 直接使用从密钥库加载的 SecretKey 时,密钥用户未经过身份验证

    我正在尝试使用 Cipher 和在 KeyStore 中加载的 SecretKey 来加密数据 但总是收到此错误 导致 android security KeyStoreException 关键用户未经过身份验证 我尝试自己创建 Secre
  • Android AutoCompleteTextView 带芯片

    我不确定我是否使用了正确的词语来描述此 UI 功能 但我已附上我希望在我的应用程序中实现的目标的快照 它由 Go SMS 使用 用户在编辑文本中键入联系人 在用户从完成下拉列表中选择联系人后 该联系人将被插入到编辑文本中 如附图所示 编辑文
  • 在没有 Wifi 的情况下获取 Android 设备的 MAC 地址

    如何获取没有 Wifi 接口的 Android 设备 例如 Android 模拟器 的网络接口的 MAC 地址 通过WifiManager返回获取的WifiInfonull EDIT 更清楚地说 我必须与本地网络上的现有网络协议 不是我设计

随机推荐

  • BES 平台 SDK之提示音的添加

    本文章是基于BES2700 芯片 其他BESxxx 芯片可做参考 如有不当之处 欢迎评论区留言指出 仅供参考学习用 BES 平台 SDK之按键的配置 谢文浩的博客 CSDN博客 关于系统按键简介可参考上一篇文章 链接如上所示 一 提示音的制
  • Python 10大可视化工具 (附详细教程)

    今天分享10个适用于多个学科的Python数据可视化库 其中有名气很大的也有鲜为人知的 1 matplotlib 保姆级教程 Matplotlib 两个直方图 matplotlib 是Python可视化程序库的泰斗 经过十几年它任然是Pyt
  • 计算软件测试数据流图独立路径,软件测试技术(2)

    最小值 其中k i 期望结果 基于k的正确平均值和总数 路径5测试用例 value i 有效输入 其中i 100 value k 最大值 其中k i 期望结果 基于k的正确平均值和总数 路径6测试用例 value i 有效输入 其中i 10
  • Basic Level 1005 继续(3n+1)猜想 (25分)

    题目 卡拉兹 Callatz 猜想已经在1001中给出了描述 在这个题目里 情况稍微有些复杂 当我们验证卡拉兹猜想的时候 为了避免重复计算 可以记录下递推过程中遇到的每一个数 例如对 n 3 进行验证的时候 我们需要计算 3 5 8 4 2
  • 50家大厂面试万字精华总结,和快手大牛的技术面谈,进阶学习资料!

    前言 MySQL 是最流行的关系型数据库管理系统 RDBMS 之一 MySQL作为一个关系型数据库管理系统 因为其速度 可靠性和适应性而备受关注 大多数人都认为在不需要事务化处理的情况下 MySQL是管理内容最好的选择 虽然功能未必很强大
  • Flutter(一)介绍、Dart语言简介

    目录 Flutter介绍 跨平台技术简介 1 跨平台自绘引擎 2 高性能 Flutter 为什么选择 Dart 语言 1 开发效率高 2 高性能 3 快速内存分配 4 类型安全和空安全 5 Dart 团队就在你身边 Flutter框架结构
  • VS2010编译静态链接MFC的OCX遇到的问题:nafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12 已经在 LIBCMTD.lib(dllm

    打开工程属性页 配置属性 gt 链接器 gt 输入 忽略特定默认库添加 LIBCMTD lib nafxcwd lib 附加依赖项添加 nafxcwd lib LIBCMTD lib 目的是调整依赖库链接顺序 其他类似的问题也可以这样解决
  • 信息安全专业好不好?

    信息安全在我国起步比较晚 国外都已经很普遍了 所以如果现在学习信息安全还可以抓到一波红利 就像很多年前的JAVA一样 而且现在国家很重视安全 很多有利政策 总之安全这块还是可以尽早加入 有前途 初入计算机行业的人或者大学计算机相关专业毕业生
  • dc-7 靶机渗透学习

    信息收集 扫描当前网段 nmap sP 192 168 202 0 24 查看开启的端口服务 nmap A p v 192 168 202 146 访问靶机的80端口 通过Wappalyzer识别出是Drupal 8 先看一下靶机的说明 不
  • 生成6位随机数字字符串的方式

    生成6位随机数字字符串的方式 方法一 方法二 今天在工作中使用到了随机生成6位数字字符串的方式 方法一 一种比较low的使用方法 使用字符串进行拼接 循环6次 话不多说上代码 内联代码片 方法一 字符串拼接随机生成6位随机数 String
  • 联邦学习的过程

    联邦学习的过程分为自治和联合两部分 自治的部分 首先 两个或两个以上的的参与方们在各自终端安装初始化的模型 每个参与方拥有相同的模型 之后参与方们可以使用当地的数据训练模型 由于参与方们拥有不同的数据 最终终端所训练的模型也拥有不同的模型参
  • private static final long serialVersionUID = 1L 的作用

    1 这句话的意思是定义程序序列化ID 2 什么是序列化 Serializable Java的一个接口 用来完成java的序列化和反序列化操作的 任何类型只要实现了Serializable接口 就可以被保存到文件中 或者作为数据流通过网络发送
  • 小程序视频播放组件《video》

    今天花了不少时间实现了在同一个页面上实现多个视频播放的功能 显示在同一个页面 可以上下拉动 效果如下图显示 具体代码如下 video wxml
  • Spring Boot项目中集成Apollo

    要在Spring Boot项目中集成Apollo 你可以按照以下步骤进行操作 步骤1 添加Apollo依赖 在你的Spring Boot项目的pom xml文件中添加Apollo依赖
  • 基于SpringBoot的校园疫情防控系统设计与实现

    1 概述 校园疫情防控系统的开发运用java技术 springboot框架 MIS的总体思想 以及Mysql等技术的支持下共同完成了该系统的开发 实现了校园疫情防控管理的信息化 使用户体验到校园疫情防控管理 管理员管理操作将更加方便 实现目
  • K8S-5--云原生基础/k8s基础及组件/二进制部署k8s集群

    一 云原生基础 CNCF 云原生容器生态系统概要 http dockone io article 3006 13年 docker项目正式发布 14年 kubernetes项目正式发布 15年 Google Redhat微软牵头成立CNCF
  • Linux route详解

    route命令用于显示和操作IP路由表 要实现两个不同的子网之间的通信 需要一台连接两个网络的路由器 或者同时位于两个网络的网关来实现 在Linux系统中 设置路由通常是 为了解决以下问题 该Linux系统在一个局域网中 局域网中有一个网关
  • 当用户在浏览器上输入url后发生了什么

    进行DNS域名解析 进行tcp连接 发起三次握手 发送一个http请求 服务器处理相关的请求 并且返回对应的结果 关闭tcp连接 浏览器将浏览器处理后的结果进行解析 浏览器将解析后的资源进行请求 并且渲染页面
  • 【翻译】为什么你现在比以往更需要混沌工程?

    大约一年前 像餐馆和杂货店这样的实体店正争先恐后地设置送货和路边取货 他们中的很多人都在生产中使用混乱工程 在推出新功能和服务之前迅速寻找失败的原因 教育平台也是如此 在短短一周的时间里 从 好的 变成了 绝对必要 企业混沌工程平台 Gre
  • Android UI设计 屏幕底部的菜单栏 动画切换Activity

    最终效果如下图 点击菜单会切换Activity 有动画效果 从早上起床就研究这个东西 因为之前一直都直接用系统提供的几个控件 从来没搞过图片背景 嵌套布局什么的 今天是第一次 没什么经验 花了一个上午才搞定 简单介绍一下思路 使用Linea