2014-05-07 4 views
0

Я работаю с пользовательским alertDialog в android и нашел проблему. Мой код прост:custom alertDialog in android

LayoutInflater inflatre = getLayoutInflater(); 
View v = inflatre.inflate(R.layout.dialog_view, null); 
AlertDialog.Builder dialog = new AlertDialog.Builder(EditPageActivity.this); 
dialog.setView(v); 
dialog.show(); 

И расположение XML является:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/bg" 
android:padding="10dp" 
android:gravity="center" > 

<Button 
    android:id="@+id/gallery_b" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Gallery" /> 

<Button 
    android:id="@+id/photo_b" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/gallery_b" 
    android:text="Take Photo" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/gallery_b" 
    android:layout_centerHorizontal="true" 
    android:text="Choose Image" 
    android:textSize="20sp" 
    android:textColor="@color/splash_font" 
    android:layout_marginBottom="10dp" /> 

Но выход, как это:

enter image description here

Чувство беспомощности после поиска Google : (... может кто-нибудь мне что-нибудь описать

+0

набор 'андроида: layout_width = "fill_parent" андроид: layout_height = "fill_parent"' к вашей основной раскладке и попытаться –

+0

удалить заполнить или использовать изображение с обратной связью по диагонали больше по высоте или просто вручную установить высоту макета –

ответ

1

Попробуйте этот макет для Dialog, он должен работать.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/bg" 
    android:padding="10dp" 
    android:gravity="center"> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:text="Choose Image" 
     android:textSize="20sp" 
     android:textColor="@color/splash_font"/> 

    <Button 
     android:id="@+id/gallery_b" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textView1" 
     android:text="Gallery" 
     android:layout_marginTop="10dp"/> 

    <Button 
     android:id="@+id/photo_b" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/gallery_b" 
     android:text="Take Photo" /> 

</RelativeLayout> 

enter image description here

+0

хорошо ... спасибо, ваш макет работал для меня .... можете ли вы описать факты, почему мой макет не работал как твой ... мой макет почти аналогичен т o ваш, хотя ... –

+0

@MostafaImran обратите внимание на этот параметр выравнивания. ' '' ' –

1

Попробуйте

Dialog dialog = new Dialog(YourActivity.this); 
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
        dialog.setContentView(R.layout.yourlayout); // your layout id 
        Button dialogButton = (Button) dialog 
          .findViewById(R.id.dialogButtonOK); // button in your layout 
        // if button is clicked, close the custom dialog 
        dialogButton.setOnClickListener(new OnClickListener() { 

         @Override 
         public void onClick(View v) { 


         } 
        }); 

        dialog.show(); 
1

// Попробуйте один:

 final Dialog dialog = new Dialog(mContext); 
     dialog.requestWindowFeature((int) Window.FEATURE_NO_TITLE); 
     dialog.setContentView(R.layout.your_layout_here); 
     WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 
     lp.copyFrom(dialog.getWindow().getAttributes()); 
     lp.width = WindowManager.LayoutParams.WRAP_CONTENT; 
     lp.height = WindowManager.LayoutParams.WRAP_CONTENT; 
     dialog.getWindow().setAttributes(lp); 
     dialog.show();