2017-01-11 4 views
0

У меня есть AlertDialog, на который я установил пользовательский вид. В макете просмотре Android Studio, это показывает, что я ожидаю макет выглядеть следующим образом:Удалите лишнее пространство из AlertDialog

enter image description here

Однако, когда приложение работает на моем Nexus 6P это выглядит следующим образом (обратите внимание на дополнительное пространство в верхней части, то есть что Я не хочу):

enter image description here

As suggested here Я попытался изменить как макет был установлен:

alertDialog2.setView(view2,0,0,0,0); 
alertDialog2.show(); 

Однако это не решило мою проблему. Любые предложения о том, как это сделать?

XML Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" android:layout_height="match_parent"> 

<TextView 
    android:text="Suggest improvements or changes, or report bugs." 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="20dp" 
    android:id="@+id/textView5" 
    android:textColor="@color/Black" 
    android:layout_marginLeft="5dp" 
    android:layout_marginRight="5dp" /> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="45dp"> 

    <EditText 
     android:layout_height="wrap_content" 
     android:inputType="textEmailAddress" 
     android:ems="10" 
     android:id="@+id/email_feedback_text" 
     android:layout_marginLeft="125dp" 
     android:layout_width="250dp" 
     android:layout_alignParentBottom="false" 
     android:layout_marginRight="5dp" /> 

    <TextView 
     android:text="E-mail*:" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="20dp" 
     android:id="@+id/textV5" 
     android:textColor="@color/Black" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="30dp" /> 
</RelativeLayout> 
</RelativeLayout> 

Java:

  AlertDialog.Builder alertDialogBuilderComplete = new AlertDialog.Builder(
           MainActivity.this); 

         alertDialogBuilderComplete.setCancelable(false); 
         alertDialogBuilderComplete.setTitle("Submit Feedback"); //Set the title of the box 
         alertDialogBuilderComplete.setMessage(""); 
         alertDialogBuilderComplete.setNegativeButton("Submit",null); 
         alertDialogBuilderComplete.setPositiveButton("Cancel", new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int id) { 
           dialog.cancel(); //when they click dismiss we will dismiss the box 
          } 
         }); 
         alertDialog2 = alertDialogBuilderComplete.create(); //create the box 
         alertDialog2.setOnShowListener(new DialogInterface.OnShowListener(){ 
          @Override 
          public void onShow(DialogInterface dialog) { 
           Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE); 
           button.setOnClickListener(new View.OnClickListener() { 
            } 
           }); 
          } 
         }); 

         alertDialog2.setView(view2,0,0,0,0); 
         alertDialog2.show(); 
+0

вы можете вставить ваш макет XML? – Maragues

+0

Обновлено, чтобы включить xml-макет – ez4nick

+0

@ ez4nick проверить ответ bro – W4R10CK

ответ

1

Удалить эту строку:

alertDialogBuilderComplete.setMessage("") 

Или изменить его на:

alertDialogBuilderComplete.setMessage(null) 
+0

Спасибо! Это будет сделано! – ez4nick

0

После того, как Вы отправили свой XML, я вижу android:layout_marginTop="20dp" сделать android:layout_marginTop="0dp"

<TextView 
    android:text="Suggest improvements or changes, or report bugs." 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="0dp" 
    android:id="@+id/textView5" 
    android:textColor="@color/Black" 
    android:layout_marginLeft="5dp" 
    android:layout_marginRight="5dp" /> 
+0

Пробовал то же самое, что и раньше. Я имею в виду пространство ниже. Отправить отзыв и в дополнение к предлагаемым улучшениям – ez4nick

+0

На какое дополнительное пространство вы ссылаетесь? Вышеприведенные отзывы? или выше предлагают улучшения ..? –

0
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" android:layout_height="match_parent"> 

<TextView 
android:text="Suggest improvements or changes, or report bugs." 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignParentTop="true" 
android:layout_centerHorizontal="true" 
// remove margin top 
android:id="@+id/textView5" 
android:textColor="@color/Black" 
android:layout_marginLeft="5dp" 
android:layout_marginRight="5dp" /> 
    ........ 
     ....... 
<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
// remove margin top, can be added margin as needed 

<EditText 
    android:layout_height="wrap_content" 
    android:inputType="textEmailAddress" 
    android:ems="10" 
    android:id="@+id/email_feedback_text" 
    android:layout_marginLeft="125dp" 
    android:layout_width="250dp" 
    android:layout_alignParentBottom="false" 
    android:layout_marginRight="5dp" /> 
    ...... 
      .......... 
    </RelativeLayout> 
+0

Удаление «marginTop» не решает проблему – ez4nick

+0

Удалил ли вы из верхней relativelayout? – W4R10CK

+0

Да. Проблема сохраняется – ez4nick