2011-11-24 48 views
2

刪除不必要的利潤我有我設計一個自定義對話框這是一個問題。我建立用於這個XML作爲的FrameLayout是根佈局,並且帶有灰色背景圖像的另一個的FrameLayout用於內容,其中,我已經加入一個TextView和兩個按鈕OK和Cancel並使用所有的該通dialog.setContentView(desired Xml Resource);
但是,當我生成特定的對話框就說明每方多餘的空格,或者我們可以說,額外的利潤是有,但我不知道它將如何刪除?請查看附帶這個問題的圖片,併爲我提供正確的解決方案。從一個自定義對話框

XML佈局:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="wrap_content"> 

    <FrameLayout android:id="@+id/rel" 
     android:layout_gravity="center_vertical" android:background="@drawable/dialog_box_bg" android:layout_width="wrap_content" android:layout_height="189dp"> 
     <TextView android:id="@+id/tv_LogoutDialog_Text" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:textColor="#424242" 
      android:text="Are you sure want to logout?" android:textSize="20dip" android:layout_gravity="center_vertical|center_horizontal"></TextView> 
     <Button android:id="@+id/btn_LogoutDialog_Cancel" android:background="@drawable/dialog_cancel_btn" 
      android:layout_marginLeft="20dip" android:layout_width="120dip" android:layout_height="42dip" android:layout_gravity="bottom|left" android:layout_marginBottom="15dip"></Button> 
     <Button android:id="@+id/btn_LogoutDialog_Ok" 
    android:background="@drawable/dialog_ok_btn_hover" 
    android:layout_width="120dip" 
    android:layout_height="42dip" android:layout_marginLeft="180dip" android:layout_gravity="bottom|right" android:layout_marginBottom="15dip" android:layout_marginRight="20dip"></Button> 
    </FrameLayout> 
</FrameLayout> 

代碼:

@Override 
    protected Dialog onCreateDialog(int id) { 
     switch (id) { 
     case 0: 
      dialog = new Dialog(HomeScreenActivity.this); 
      dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
      dialog.setContentView(R.layout.logoutdialog); 
      btn_cancel = (Button)dialog.findViewById(R.id.btn_LogoutDialog_Cancel); 
      btn_ok = (Button)dialog.findViewById(R.id.btn_LogoutDialog_Ok); 

      btn_cancel.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View arg0) { 

        dismissDialog(0); 

       } 
      }); 

      btn_logout.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View arg0) { 

        Intent intent = new Intent(HomeScreenActivity.this,LoginScreen.class); 
        startActivity(intent); 

       } 
      }); 
     return dialog; 
     } 
     return null; 
    } 

在此先感謝。 enter image description here

+0

你找到了一個解決方案? – Gunhan

回答

0

不要使用

dialog.setContentView(R.layout.logoutdialog); 

使用

LayoutInflater class to set Dialog content view 

這裏是鏈接(Check),你可以得到的想法也許這可以幫助你。

+0

它對我不起作用,結果保持不變。 –

+0

把XMLNS:機器人=「http://schemas.android.com/apk/res/android」 在內部框架佈局和除去然後外佈局檢查。 –

+0

不,結果仍然保持不變。 –