2011-11-24 70 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

不,结果仍然保持不变。 –