我创建了一个自定义对话框,我通过 RelativeLayout 动态地将 View 放入其中。每次显示对话框时,它都会很好地显示我所有的 subview ,但它在顶部有一些我无法解释的空间。我假设这是为对话框的“标题”保留的(我不会)。有没有一种方法可以删除该空格并让我的自定义对话框只包含我放入的内容?
这是布局的 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();
无论我做什么或如何更改布局文件,我总是在顶部有那个缓冲区,我该如何摆脱它?
最佳答案
将此代码放入类构造函数或 onCreate() 方法中:
requestWindowFeature(Window.FEATURE_NO_TITLE);
必须在调用setContentView方法之前。
关于android - 从自定义对话框顶部删除额外的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3542224/