Android仿QQ空间底部菜单示例代码

Android仿QQ空间底部菜单示例代码,第1张

概述之前曾经在网上看到Android仿QQ空间底部菜单的Demo,发现这个Demo有很多Bug,布局用了很多神秘数字。于是研究了一下QQ空间底部菜单的实现,自己写了一个,供大家参考。效果如下图所示: 1、实现原理很简单,底部 之前曾经在网上看到AndroID仿QQ空间底部菜单的Demo,发现这个Demo有很多BUG,布局用了很多神秘数字。于是研究了一下QQ空间底部菜单的实现,自己写了一个,供大家参考。效果如下图所示:

 

1、实现原理很简单,底部菜单是一个水平分布的linearLayout,里面又是五个linearLayout,它们的layout_weight都为1,意味着底部菜单的子控件将屏幕宽度平均分为5部分。五个linearLayout除了中间那个,其余都在里面放置ImageVIEw和TextVIEw(中间先空着,什么都不放,后面用来放底盘和加号的)。
2、中间的加号和底盘是用FramLayout实现的,现在底部居中的位置放置底盘,然后在相同位置放置加号,就搞定了。
3、设置加号的触摸事件,d窗是用PopupWindow实现的,然后再把加号的图片替换成乘号就搞定了。代码如下所示:
ButtomMenuActivity.java:
复制代码 代码如下:
package com.shamoo.qqbuttommenu;
import com.shamoo.qqbuttommenu.R;
import androID.app.tabactivity;
import androID.content.Context;
import androID.content.Intent;
import androID.graphics.color;
import androID.graphics.drawable.BitmapDrawable;
import androID.os.Bundle;
import androID.vIEw.Gravity;
import androID.vIEw.LayoutInflater;
import androID.vIEw.MotionEvent;
import androID.vIEw.VIEw;
import androID.vIEw.VIEw.OnClickListener;
import androID.vIEw.VIEw.OntouchListener;
import androID.vIEw.WindowManager;
import androID.Widget.AbsListVIEw;
import androID.Widget.FrameLayout;
import androID.Widget.ImageVIEw;
import androID.Widget.linearLayout;
import androID.Widget.PopupWindow;
import androID.Widget.PopupWindow.OndismissListener;
import androID.Widget.Radiobutton;
import androID.Widget.TabHost;
public class ButtomMenuActivity extends tabactivity {
FrameLayout fmpan;
TabHost tabHost;
ImageVIEw image;
FrameLayout fm;
LayoutInflater inflater;
private Radiobutton tab_home,tab_second;
PopupWindow popup;

public voID onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentVIEw(R.layout.tab);
initVIEw();
fm.setonClickListener(new OnClickListener() {
public voID onClick(VIEw v) {
image.setimageResource(R.drawable.toolbar_plusback);
showWindow(fmpan);
}
});
}
private voID initVIEw() {
inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
fmpan = (FrameLayout)findVIEwByID(R.ID.tab1);
fm = (FrameLayout)findVIEwByID(R.ID.btn_ck);
image = (ImageVIEw)findVIEwByID(R.ID.image1);
}

private voID showWindow(VIEw parent) {
if(popup == null) {
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
VIEw vIEw = layoutInflater.inflate(R.layout.write_tab,null);
// 创建一个PopuWIDow对象
popup = new PopupWindow(vIEw,linearLayout.LayoutParams.MATCH_PARENT,320);
// 设置焦点在d窗上
popup.setFocusable(true);
// 设置允许在外点击消失
popup.setoutsIDetouchable(true);
// 设置d窗消失事件监听
popup.setondismissListener(new OndismissListener() {
public voID ondismiss() {
// Todo auto-generated method stub
image.setimageResource(R.drawable.toolbar_plus);
}
});
// 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
popup.setBackgroundDrawable(new BitmapDrawable());
popup.settouchInterceptor(new OntouchListener() {
public boolean ontouch(VIEw vIEw,MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_OUTSIDE) {
popup.dismiss();
image.setimageResource(R.drawable.toolbar_plus);
return true;
}
return false;
}
});
}
if(!popup.isShowing()) {
popup.showAsDropDown(parent,Gravity.CENTER,0);
}
}
}

tab.xml:
复制代码 代码如下:
<?xml version="1.0" enCoding="utf-8"?>
<TabHost xmlns:androID="http://schemas.androID.com/apk/res/androID"
androID:ID="@androID:ID/tabhost"
androID:layout_wIDth="fill_parent"
androID:layout_height="fill_parent" >
<FrameLayout
androID:ID="@+ID/l1"
androID:layout_wIDth="fill_parent"
androID:layout_height="fill_parent" >
<FrameLayout
androID:ID="@androID:ID/tabcontent"
androID:layout_wIDth="fill_parent"
androID:layout_height="fill_parent"
/>
<TabWidget
androID:ID="@androID:ID/tabs"
androID:layout_wIDth="fill_parent"
androID:layout_height="10.0px"
androID:visibility="gone" />
<relativeLayout
androID:layout_wIDth="fill_parent"
androID:layout_height="fill_parent">
<include
androID:layout_alignParentBottom="true"
androID:ID="@+ID/tab1"
androID:layout_wIDth="fill_parent"
androID:layout_height="wrap_content"
layout = "@layout/test" />
</relativeLayout>
</FrameLayout>
</TabHost>

test.xml:
复制代码 代码如下:
<?xml version="1.0" enCoding="utf-8"?>
<FrameLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"
androID:layout_wIDth="fill_parent"
androID:layout_height="wrap_content"
androID:background="@drawable/toolbar_bg" >
<linearLayout
androID:layout_wIDth="fill_parent"
androID:layout_height="wrap_content"
androID:layout_gravity="bottom"
androID:gravity="center_horizontal"
androID:orIEntation="horizontal" >
<linearLayout
androID:layout_wIDth="fill_parent"
androID:layout_height="wrap_content"
androID:orIEntation="vertical"
androID:layout_weight="1" >
<ImageVIEw
androID:layout_wIDth="wrap_content"
androID:layout_height="wrap_content"
androID:layout_gravity="top|center"
androID:src="@drawable/tab_timeFeed_opacity"
androID:visibility="visible" />
<TextVIEw
androID:layout_wIDth="wrap_content"
androID:layout_height="wrap_content"
androID:layout_gravity="bottom|center"
androID:text="好友动态"
androID:textSize="10.0dip"
androID:visibility="visible" />
</linearLayout>
<linearLayout
androID:layout_wIDth="fill_parent"
androID:layout_height="wrap_content"
androID:orIEntation="vertical"
androID:layout_weight="1" >
<ImageVIEw
androID:layout_wIDth="wrap_content"
androID:layout_height="wrap_content"
androID:layout_gravity="top|center"
androID:src="@drawable/tab_Feedback_opacity"
androID:visibility="visible" />
<TextVIEw
androID:layout_wIDth="wrap_content"
androID:layout_height="wrap_content"
androID:layout_gravity="bottom|center"
androID:text="与我相关"
androID:textSize="10.0dip"
androID:visibility="visible" />
</linearLayout>
<linearLayout
androID:layout_wIDth="fill_parent"
androID:layout_height="wrap_content"
androID:orIEntation="vertical"
androID:layout_weight="1" />
<linearLayout
androID:layout_wIDth="fill_parent"
androID:layout_height="wrap_content"
androID:orIEntation="vertical"
androID:layout_weight="1" >
<ImageVIEw
androID:layout_wIDth="wrap_content"
androID:layout_height="wrap_content"
androID:layout_gravity="top|center"
androID:src="@drawable/tab_myzone_opacity"
androID:visibility="visible" />
<TextVIEw
androID:layout_wIDth="wrap_content"
androID:layout_height="wrap_content"
androID:layout_gravity="bottom|center"
androID:text="主页"
androID:textSize="10.0dip"
androID:visibility="visible" />
</linearLayout>
<linearLayout
androID:layout_wIDth="fill_parent"
androID:layout_height="wrap_content"
androID:orIEntation="vertical"
androID:layout_weight="1" >
<ImageVIEw
androID:layout_wIDth="wrap_content"
androID:layout_height="wrap_content"
androID:layout_gravity="top|center"
androID:src="@drawable/tab_appList_opacity"
androID:visibility="visible" />
<TextVIEw
androID:layout_wIDth="wrap_content"
androID:layout_height="wrap_content"
androID:layout_gravity="bottom|center"
androID:text="应用"
androID:textSize="10.0dip"
androID:visibility="visible" />
</linearLayout>
</linearLayout>
<FrameLayout
androID:layout_wIDth="wrap_content"
androID:layout_height="wrap_content"
androID:layout_gravity="center_horizontal"
androID:layout_weight="1" >
<ImageVIEw
androID:layout_wIDth="wrap_content"
androID:layout_height="wrap_content"
androID:layout_gravity="center"
androID:src="@drawable/toolbar_write_bg" />
</FrameLayout>
<FrameLayout
androID:ID="@+ID/btn_ck"
androID:layout_wIDth="wrap_content"
androID:layout_height="wrap_content"
androID:layout_gravity="center"
androID:layout_weight="1" >
<ImageVIEw
androID:ID="@+ID/image1"
androID:layout_wIDth="wrap_content"
androID:layout_height="wrap_content"
androID:layout_gravity="center"
androID:layout_margintop="2.0dip"
androID:src="@drawable/toolbar_plus" />
</FrameLayout>
</FrameLayout>

这个Demo只是仿着来玩,可能有些地方写得不怎么规范。如果有什么问题,希望大家可以指出,谢谢! 您可能感兴趣的文章:安卓(Android)实现3DTouch效果Android左右滑出菜单实例分析android底部菜单栏实现原理与代码android popwindow实现左侧d出菜单层及PopupWindow主要方法介绍基于Android实现点击某个按钮让菜单选项从按钮周围指定位置d出Android ListView长按d出菜单二种实现方式示例Android界面设计(APP设计趋势 左侧隐藏菜单右边显示content)Android开发技巧之我的菜单我做主(自定义菜单)Android实现原生侧滑菜单的超简单方式Android实现类似3D Touch菜单功能 总结

以上是内存溢出为你收集整理的Android仿QQ空间底部菜单示例代码全部内容,希望文章能够帮你解决Android仿QQ空间底部菜单示例代码所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1142901.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存