请问一个出现在整个view上方的菜单是怎样制作的?
如图,出现的view切换菜单,这个是通过什么方法制作的?
因为要兼容之前的设备,所以希望方法能在2.1及以上版本通过,谢谢。
[解决办法]
有2种方法实现:
1、用透明的Dialog;
2、将主体布局用FrameLayout,然后这个菜单层默认是隐藏的,需要的时候才显示出来。
[解决办法]
ActionBar吧
[解决办法]
用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或者AlertDialog
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>
样式跟那个差不多
[解决办法]
[解决办法]
看楼主等级 应该是个高手 在此只做提示 android3.0里有个组件被之后版本沿用 fragment 使用简单方便操作 3.0版本一下 可自己倒jar包实现 具体jar包地址 自己官网找