请问一个出现在整个view上方的菜单是怎样制作的? 本帖最后由 itakeblue 于 2012-09-15 00:10:11 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有2种方法实现:1、用透明的Dialog;2、将主体布局用FrameLayout,然后这个菜单层默认是隐藏的,需要的时候才显示出来。 用Dialog可以实现,我已经实现了这样的功能[code=Java]<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/shortcutPanel" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingTop="9dip" android:paddingBottom="3dip" android:paddingLeft="3dip" android:paddingRight="1dip" android:majorWeight="0.65" android:minorWeight="0.9" android:layout_gravity="bottom" android:gravity="center" android:background="@drawable/br_iphone_touchkey_bg"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:layout_weight="1" > <ImageView android:id="@+id/touch_backkey" android:tag="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" style="?android:attr/buttonStyle" android:background="@drawable/br_iphone_touch_back" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:layout_weight="1" > <ImageView android:id="@+id/touch_homekey" android:tag="2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" style="?android:attr/buttonStyle" android:background="@drawable/br_iphone_touch_home" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:layout_weight="1" > <ImageView android:id="@+id/touch_menukey" android:tag="3" android:layout_width="wrap_content" android:layout_height="wrap_content" style="?android:attr/buttonStyle" android:layout_gravity="center" android:background="@drawable/br_iphone_touch_menu" /> </LinearLayout></LinearLayout>code]这个就是布局文件 前一段时间也遇到过这样的问题,这个可以用dialog实现,关键是,要设置activity的主题为Holo,或者自己定义主题,里面要带有 <item name="panelMenuIsCompact">true</item> <item name="panelMenuListWidth">250dip</item> <item name="panelMenuListTheme">@android:style/Theme.Holo.Light.CompactMenu</item>的主题就好了,这会改变dialog的样式。 用popupWindow或者AlertDialogpopupWindow实现//显示PopupWindow// LayoutInflater mLayoutInflater = (LayoutInflater) VideoActivity.this // .getSystemService(LAYOUT_INFLATER_SERVICE); // View share_popunwindwow = mLayoutInflater.inflate( // R.layout.share, null); // final PopupWindow mPopupWindow = new PopupWindow(share_popunwindwow, LayoutParams.FILL_PARENT, // LayoutParams.WRAP_CONTENT); // // mPopupWindow.showAtLocation(findViewById(R.id.main), Gravity.RIGHT|Gravity.BOTTOM, 0, 0); AlertDialog实现LayoutInflater factory = LayoutInflater.from(context); final View dialogView = factory.inflate(R.layout.share, null); final AlertDialog dlg = new AlertDialog.Builder( context) .setTitle(context.getResources().getString(R.string.share)) .setView(dialogView).create(); dlg.show(); dlg.getWindow().setLayout(BaseApplication.winWidth, LayoutParams.WRAP_CONTENT); 布局代码都是下面这个<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@color/black"> <Button android:id="@+id/btn_faceBook" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/share_to_facebook" /> <Button android:id="@+id/btn_xinlang" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/share_to_xinlang" /> <Button android:id="@+id/btn_cancle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/cancle" /></LinearLayout>样式跟那个差不多 Holo主题是3.0以上才有的。楼主要兼容2.1用Dialog可以试试其他属性,或许可以。 看楼主等级 应该是个高手 在此只做提示 android3.0里有个组件被之后版本沿用 fragment 使用简单方便操作 3.0版本一下 可自己倒jar包实现 具体jar包地址 自己官网找 (求助!) Android Socket发送数据延时! 真机如何访问PC服务器? 两个view以拖动方式切换,该如何实现? 怎么把简体中文转换成繁体中文 android ndk 杀掉指定PID的进程 哪里有Android Map的开发文档 请大家谈谈Google退出中国对Android影响多大??Android市场如何 为什么我开发的安卓软件 MIUI能打开正常 安卓系统就会闪退 仿淘宝的页面疑问 更新Android开发环境后,写程序就没有图标了 怎样做到 当点击返回按钮的时候 不在重复检查是否需要升级?
1、用透明的Dialog;
2、将主体布局用FrameLayout,然后这个菜单层默认是隐藏的,需要的时候才显示出来。
[code=Java]
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/shortcutPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="9dip"
android:paddingBottom="3dip"
android:paddingLeft="3dip"
android:paddingRight="1dip"
android:majorWeight="0.65"
android:minorWeight="0.9"
android:layout_gravity="bottom"
android:gravity="center"
android:background="@drawable/br_iphone_touchkey_bg">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="1" >
<ImageView
android:id="@+id/touch_backkey"
android:tag="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
style="?android:attr/buttonStyle"
android:background="@drawable/br_iphone_touch_back" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="1" >
<ImageView
android:id="@+id/touch_homekey"
android:tag="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
style="?android:attr/buttonStyle"
android:background="@drawable/br_iphone_touch_home" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="1" >
<ImageView
android:id="@+id/touch_menukey"
android:tag="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/buttonStyle"
android:layout_gravity="center"
android:background="@drawable/br_iphone_touch_menu" />
</LinearLayout>
</LinearLayout>code]
这个就是布局文件
<item name="panelMenuListWidth">250dip</item>
<item name="panelMenuListTheme">@android:style/Theme.Holo.Light.CompactMenu</item>的主题就好了,这会改变dialog的样式。
popupWindow实现
//显示PopupWindow
// LayoutInflater mLayoutInflater = (LayoutInflater) VideoActivity.this
// .getSystemService(LAYOUT_INFLATER_SERVICE);
// View share_popunwindwow = mLayoutInflater.inflate(
// R.layout.share, null);
// final PopupWindow mPopupWindow = new PopupWindow(share_popunwindwow, LayoutParams.FILL_PARENT,
// LayoutParams.WRAP_CONTENT);
//
// mPopupWindow.showAtLocation(findViewById(R.id.main), Gravity.RIGHT|Gravity.BOTTOM, 0, 0); AlertDialog实现
LayoutInflater factory = LayoutInflater.from(context);
final View dialogView = factory.inflate(R.layout.share, null);
final AlertDialog dlg = new AlertDialog.Builder(
context)
.setTitle(context.getResources().getString(R.string.share))
.setView(dialogView).create();
dlg.show();
dlg.getWindow().setLayout(BaseApplication.winWidth, LayoutParams.WRAP_CONTENT); 布局代码都是下面这个
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/black"> <Button
android:id="@+id/btn_faceBook"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/share_to_facebook" /> <Button
android:id="@+id/btn_xinlang"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/share_to_xinlang" /> <Button
android:id="@+id/btn_cancle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/cancle" /></LinearLayout>
样式跟那个差不多
楼主要兼容2.1
用Dialog可以试试其他属性,或许可以。