java - 换行内容不适用于对话框

标签 java android listview dialog

我的目标是创建一个包含其内容高度的对话框,如下图所示。

enter image description here

我的问题是我的对话框想要匹配其父对话框,如下图所示。高度应停止在项目“asdf”处,并且“asdf”下方的空白不应存在。

enter image description here

这是我稍后的代码:

private void showPopupEventTest(final String Cardid) {
        Dialog dialog = new Dialog(getActivity(), R.style.Theme_AppCompat_Dialog_Alert);
        dialog.getWindow().setLayout(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
        dialog.setContentView(R.layout.fragment_event);
        SwipeRefreshLayout swipeRefreshLt = (SwipeRefreshLayout) dialog.findViewById(R.id.swipeRefreshLt);
        ListView lv = (ListView) dialog.findViewById(R.id.Contacts_list_view);
        SearchView SearchET = (SearchView) dialog.findViewById(R.id.SearchET);
        LinearLayout layoutLinearLayout = (LinearLayout) dialog.findViewById(R.id.layoutLinearLayout);
        EventAdaptor myAdapter = new EventAdaptor(getContext(), ArrayList_EventObject);
        lv.setAdapter(myAdapter);
        dialog.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        dialog.show();

    }

这是布局:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/layoutLinearLayout"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:paddingTop="8dp">

    <SearchView
        android:id="@+id/SearchET"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:iconifiedByDefault="false" />

    <android.support.v4.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:id="@+id/swipeRefreshLt"
        android:layout_height="wrap_content">

        <ListView
            android:id="@+id/Contacts_list_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </android.support.v4.widget.SwipeRefreshLayout>

</LinearLayout>

我做错了什么?

最佳答案

试试这个

Window window = customDialog.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
window.setGravity(Gravity.CENTER);
customDialog.show();

关于java - 换行内容不适用于对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45521231/

相关文章:

android - onclick 事件即使在长按时也会执行

java - ListView 刷新而不通知DataSetChanged

java - Tomcat:自定义错误页面不工作

Java Hashmap 和已知索引的二维数组性能

用于选择一个或两个的 JAVA UI 元素

android - 两个 Pane 布局 + DrawerLayout : replace main content

java - 动态更新 Jlist

eclipse 调试透视图中的 android 系统统计信息

WPF ListView 设置 SelectedItem

Android:无限滚动 - ListView 和 Cursor