Siddharth
Siddharth

Reputation: 9574

Options Menu dialog showing a very small width

I have a options menu, and the item on that shows a dialog. For some reason its show up with very small width. I wonder why. Below is dialog code and the optionsuserdetails xml. I know I am missing something really silly. Sorry for the long code, but the problem could be anywhere in this options menu display.

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>

Edit : 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

Upvotes: 0

Views: 465

Answers (3)

ElefantPhace
ElefantPhace

Reputation: 3814

try adding this after userDetails.setContentView()

userDetails.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

Upvotes: 2

Neha Nathani
Neha Nathani

Reputation: 544

Okay. Then If userDetails is a dialog, instead of using setContentView() , why don't you use setContentView(id,layout params). If you want to decide spacing of elements in your dialog then you can use userDetails.setView(mEditText, 10, 10, 10, 10);

Upvotes: 1

Neha Nathani
Neha Nathani

Reputation: 544

Seems like the drawable you are using i.e. roundcornersgreyback is of very small width. Try using a larger image for the same. Make sure you are placing the image in the correct drawable folder with respect to your device target and image resolution(i.e. hdpi, mdpi, ldpi etc)

Upvotes: 0

Related Questions