private void show_menu_dlg() { //加载对话框资源界面 LayoutInflater factory = LayoutInflater.from(this.getContext()); final View dlgview = factory.inflate(R.layout.player_menu, null); AlertDialog.Builder dlg_login = new AlertDialog.Builder(this.getContext()); //将对话框布局设置到视图 dlg_login.setView(dlgview); //创建 并显示对话框 AlertDialog dlg = dlg_login.create(); //设置对话框位置 LayoutParams lp = dlg.getWindow().getAttributes(); //dlg.getWindow().setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); lp.x = m_screen_width - 64; lp.width = 64; dlg.getWindow().setAttributes(lp); dlg.setCanceledOnTouchOutside(true); dlg.show(); }
布局文件:
XML/HTML code?123456789101112131415161718192021222324252627282930313233343536373839404142 <?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="fill_parent" android:background="#000000" android:orientation="vertical" > <ImageButton android:id="@+id/playermenu_previous" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:padding="0dp" android:src="@drawable/up" /> <ImageButton android:id="@+id/playermenu_mode" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:padding="0dp" android:src="@drawable/play" /> <ImageButton android:id="@+id/playermenu_next" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:padding="0dp" android:src="@drawable/down" /> <ImageButton android:id="@+id/playermenu_relogin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:padding="0dp" android:src="@drawable/relogin" /> " </LinearLayout>
用弹出框模拟菜单,显示在右侧边
private void show_menu_dlg() { //加载对话框资源界面 LayoutInflater factory = LayoutInflater.from(this.getContext()); final View dlgview = factory.inflate(R.layout.player_menu, null); AlertDialog.Builder dlg_login = new AlertDialog.Builder(this.getContext()); //将对话框布局设置到视图 dlg_login.setView(dlgview); //创建 并显示对话框 AlertDialog dlg = dlg_login.create(); dlg.show(); //设置对话框位置 LayoutParams lp = dlg.getWindow().getAttributes(); //dlg.getWindow().setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); lp.x = m_screen_width - 64; lp.width = 64; dlg.getWindow().setAttributes(lp); dlg.setCanceledOnTouchOutside(true); }