0

我有一个选项菜单,上面的项目显示一个对话框。由于某种原因,它以非常小的宽度显示。我想知道为什么。下面是对话框代码和 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>

编辑:可绘制

<?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 主屏幕

4

3 回答 3

2

尝试在 userDetails.setContentView() 之后添加它

userDetails.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
于 2013-02-28T06:34:23.757 回答
1

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

于 2013-02-28T06:45:48.473 回答
0

似乎您正在使用的drawable,即roundcornersgreyback 的宽度非常小。尝试使用更大的图像。确保根据设备目标和图像分辨率(即 hdpi、mdpi、ldpi 等)将图像放置在正确的可绘制文件夹中

于 2013-02-28T06:33:53.830 回答