简体   繁体   English

在Android中使用自定义布局调整对话框的高度

[英]Adjust the height of a Dialog with custom layout in Android

I have a dialog with custom layout, everything is working fine, except there is a big empty spaces at the top which i cannot remove. 我有一个具有自定义布局的对话框,一切工作正常,除了顶部的空白处无法删除之外。

Any suggestion how i can remove that empty space. 任何建议,我如何可以删除该空白区域。

Here is my Code: 这是我的代码:

final Dialog dialog = new Dialog(ConferenceDetailsActivity.this);
dialog.setContentView(R.layout.l_custom_dialog_name);

final CustomEditText nameText = (CustomEditText) dialog.findViewById(R.id.confNameFld);
nameText.setText(mConferenceDetails.getConferenceName());

Button button = (Button) dialog.findViewById(R.id.dialogButtonOK);
button.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {

        final CustomEditText nameText = (CustomEditText) dialog.findViewById(R.id.confNameFld);
        String text = nameText.getText().toString();

        dialog.dismiss();

    }
});

dialog.show();

My xml Layout: 我的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">

    <ImageView
        android:id="@+id/nameBackground"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/name_badge"
        android:layout_alignParentTop="true" />

    <com.invosys.iconference.CustomControls.CustomEditText
        android:id="@+id/confNameFld"
        android:layout_height="45dp"
        android:layout_width="wrap_content"
        android:layout_marginTop="100dp"
        android:layout_marginBottom="20dp"
        android:layout_alignTop="@+id/nameBackground"
        android:layout_alignBottom="@+id/nameBackground"
        android:layout_alignLeft="@+id/nameBackground"
        android:layout_alignRight="@+id/nameBackground"
        android:background="@null"
        android:ems="10"
        android:hint="@string/namePlaceholder"
        android:gravity="center"
        android:isScrollContainer="false"
        android:inputType="textFilter|textNoSuggestions"
        android:textColor="@color/ECharcoalColor" />

    <Button
        android:id="@+id/dialogButtonOK"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text=" Ok "
        android:layout_below="@+id/nameBackground"
        android:layout_alignLeft="@+id/nameBackground"
        android:layout_alignRight="@+id/nameBackground" />


在此处输入图片说明

.......................... .............................

After i used this piece of code the size is reduced but it is still not unto the task; 使用完这段代码后,虽然大小有所减小,但仍然不适合该任务;

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before setContentView    
dialog.setContentView(R.layout.logindialog);

在此处输入图片说明

You can try this: 您可以尝试以下方法:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before setContentView    
dialog.setContentView(R.layout.logindialog);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM