我的目标是创建一个包含其内容高度的对话框,如下图所示。
我的问题是我的对话框想要匹配其父对话框,如下图所示。高度应停止在项目“asdf”处,并且“asdf”下方的空白不应存在。
这是我稍后的代码:
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/