选项菜单对话框显示非常小的宽度

时间:2013-02-28 06:24:18

标签: android android-dialog android-optionsmenu

我有一个选项菜单,其上的项目显示一个对话框。出于某种原因,它的宽度非常小。我想知道为什么。下面是对话框代码和optionsuserdetails xml。我知道我错过了一些非常愚蠢的东西。对于长代码很抱歉,但问题可能出在此选项菜单显示的任何位置。

case God.USER_DETAILS:
            userDetails = new Dialog(this);
            userDetails.requestWindowFeature(Window.FEATURE_NO_TITLE);
            userDetails.setContentView(R.layout.optionsuserdetails);
            userDetails.setCancelable(true);
            userName = (TextView) userDetails.findViewById(R.id.userName);
            userName.setText(God.appConfiguration.getString(God.nameKey, "-"));
            drivingLicense = (TextView) userDetails.findViewById(R.id.drivingLicense);
            drivingLicense.setText(God.appConfiguration.getString(God.drivingLicenseKey, "-"));
            vehicleNumber = (TextView) userDetails.findViewById(R.id.vehicleNumber);
            vehicleNumber.setText(God.appConfiguration.getString(God.vehicleRegistrationNumberKey,
                    "-"));
            phoneNumber = (TextView) userDetails.findViewById(R.id.phoneNumber);
            phoneNumber.setText(God.appConfiguration.getString(God.phoneNumberKey, "-"));
            userDetails.show();
            break;

<?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:background="@drawable/roundcornersgreyback"
    android:orientation="vertical" >


    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Personal Details"
        android:textColor="#990000"
        android:textSize="20sp" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="These are the details you have provided during registration."
        android:textColor="#666666"
        android:textSize="10sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#cccccc" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Name"
        android:textColor="#000000"
        android:textSize="16sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/userName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is the name you provided during registration."
        android:textColor="#222222"
        android:textSize="12sp" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Driving License Number"
        android:textColor="#000000"
        android:textSize="16sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/drivingLicense"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="This is the driving license number you provided during registration."
        android:textColor="#222222"
        android:textSize="12sp" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="License Plate (Vehicle)"
        android:textColor="#000000"
        android:textSize="16sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/vehicleNumber"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="This is the license plate number of the vehicle you are driving."
        android:textColor="#222222"
        android:textSize="12sp" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Phone Number"
        android:textColor="#000000"
        android:textSize="16sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/phoneNumber"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="This is the phone number you provided during registration."
        android:textColor="#222222"
        android:textSize="12sp" />

</LinearLayout>

编辑:drawable

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#eeeeee" />

    <stroke
        android:width="2dp"
        android:color="#cccccc" />

    <padding
        android:bottom="5dp"
        android:left="5dp"
        android:right="5dp"
        android:top="5dp" />

    <corners
        android:bottomLeftRadius="7dp"
        android:bottomRightRadius="7dp"
        android:topLeftRadius="7dp"
        android:topRightRadius="7dp" />

</shape>

taxeeta home screen

3 个答案:

答案 0 :(得分:2)

尝试在userDetails.setContentView()

之后添加它
userDetails.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

答案 1 :(得分:1)

好。然后,如果userDetails是一个对话框,而不是使用setContentView(),为什么不使用setContentView(id,layout params)。如果要确定对话框中元素的间距,则可以使用userDetails.setView(mEditText,10,10,10,10);

答案 2 :(得分:0)

看起来像你正在使用的drawable,即roundcornersgreyback的宽度非常小。尝试使用更大的图像。确保将图像放在与设备目标和图像分辨率相关的正确可绘制文件夹中(即hdpi,mdpi,ldpi等)