3

我创建了一个自定义对话框,我通过RelativeLayout 动态地将视图放入其中。每次显示对话框时,它都会显示我所有的子视图,但它在顶部有一些我无法解释的空间。我假设这是为对话框的“标题”保留的(我不会有)。有没有办法删除该空间并让我的自定义对话框只包装我放入的内容?

这是布局的xml:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
  <RelativeLayout
     android:id="@+id/handlay"
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" />  
</LinearLayout>

顺便说一句,我尝试将相对布局作为父节点,结果相同。

这是自定义对话框的 .java。

public class HandResults extends Dialog implements DialogInterface {
    HandResults hr;
    Timer myTimer;
    RelativeLayout handrl;


    // constructor sets the layout view to handresult layout
    public HandResults(Context context) {
        super(context);
        setContentView(R.layout.handresults);
        hr = this;

    }

    // create a timer to remove the dialog after 3 seconds
    public void showHands(){
        this.show();
        myTimer = null;
        myTimer = new Timer();
        myTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                hr.cancel(); 
            }
        }, 3000);

    }
}

这是我如何调用对话框:

HandResults mhr = new HandResults(this);
mhr.showHands();

无论我做什么或如何更改布局文件,我总是在顶部有那个缓冲区,我怎样才能摆脱它?

4

1 回答 1

18

将此代码放入类构造函数或 onCreate() 方法中:

    requestWindowFeature(Window.FEATURE_NO_TITLE);

必须在调用 setContentView 方法之前。

于 2010-08-23T15:32:28.470 回答