开发者

Designer Layout doesn't show correctly in Custom Dialog

开发者 https://www.devze.com 2023-03-21 10:51 出处:网络
I designed a setting dialog layout here: <?xml version=\"1.0\" encoding=\"utf-8\"?> <LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"

I designed a setting dialog layout here:

<?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:"
      开发者_JAVA百科      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>

This is the preview of that layout (and it is correct):

Designer Layout doesn't show correctly in Custom Dialog

However, when inside Dialog, it is like this:

Designer Layout doesn't show correctly in Custom Dialog

I don't know why there's always a blank space at the top, it happens in all my project, then, the dialog is completely ruined in this project. Please help me.


for remove black space try this line in your code of dialog..

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

and set property

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

for top two parent layout.. in your case set this property for top two linearlayout.


xml file

<?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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号