AlertDialog对话框大小设置
设置了宽度后和不设置都是一样的大小
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 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);
}