Макет дизайнера не отображается правильно в пользовательском диалоге - PullRequest
1 голос
/ 19 июля 2011

Я разработал макет диалога настроек здесь:

<?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:orientation="vertical" android:padding="10dip"
    android:weightSum="1" android:gravity="center">
    <LinearLayout android:id="@+id/linearLayout1"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:orientation="vertical" android:layout_weight="1">

        <TextView android:text="Sound Options:"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:layout_width="wrap_content" android:id="@+id/textView1"
            android:layout_height="wrap_content"></TextView>

        <LinearLayout android:id="@+id/linearLayout2"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:gravity="center_vertical" android:paddingLeft="5dip">

            <TextView android:text="Background Sounds:"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:layout_width="wrap_content" android:id="@+id/textView2"
                android:layout_height="wrap_content"></TextView>
            <ToggleButton android:text="ToggleButton" android:id="@+id/butBackgroundSound"
                android:layout_height="wrap_content" android:layout_width="wrap_content"></ToggleButton>

        </LinearLayout>

        <LinearLayout android:id="@+id/linearLayout3"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:gravity="center_vertical" android:paddingLeft="5dip">

            <TextView android:text="Effect Sounds:"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:layout_width="wrap_content" android:id="@+id/textView2"
                android:layout_height="wrap_content"></TextView>
            <ToggleButton android:text="ToggleButton" android:id="@+id/butEffectSound"
                android:layout_width="wrap_content" android:layout_height="wrap_content"></ToggleButton>

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

Это предварительный просмотр этого макета (и он правильный):

enter image description here

Однако, когда внутри Dialog, это выглядит так:

enter image description here

Я не знаю, почему сверху всегда есть пустое место, это происходит во всех моих проектах, тогда диалог полностью разрушен в этом проекте. Пожалуйста, помогите мне.

Ответы [ 2 ]

3 голосов
/ 19 июля 2011

для удаления пробела попробуйте эту строку в вашем коде диалога ..

Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

и установите свойство

  android:layout_width="fill_parent" android:layout_height="fill_parent"

для двух верхних родительских макетов .. в вашем случае установитесвойство для двух верхних линейных разметок.

2 голосов
/ 19 июля 2011

XML-файл

<?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:orientation="vertical" android:padding="10dip">

    <RelativeLayout android:id="@+id/linearLayout1"
        android:layout_width="fill_parent" android:layout_height="fill_parent">

        <TextView android:text="Sound Options:"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:layout_width="wrap_content" android:id="@+id/textView1"
            android:layout_height="wrap_content" android:layout_alignParentTop="true"></TextView>


        <TextView android:text="Background Sounds:"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_width="wrap_content" android:id="@+id/textView2"
            android:layout_height="wrap_content" android:layout_below="@+id/textView1"></TextView>
        <ToggleButton android:text="ToggleButton" android:id="@+id/butBackgroundSound"
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:layout_toRightOf="@+id/textView2" android:layout_below="@+id/textView1"></ToggleButton>


        <TextView android:text="Effect Sounds:"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_width="wrap_content" android:id="@+id/textView3"
            android:layout_height="wrap_content" android:layout_below="@+id/butBackgroundSound"></TextView>
        <ToggleButton android:text="ToggleButton" android:id="@+id/butEffectSound"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/textView3" android:layout_below="@+id/butBackgroundSound"></ToggleButton>



    </RelativeLayout>

</LinearLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...