Android 显示对话框后,如何禁用DialogFragment以调整大小?
我在LinearLayout中包含的DialogFragment中使用listviewAndroid 显示对话框后,如何禁用DialogFragment以调整大小?,android,android-dialogfragment,autosize,Android,Android Dialogfragment,Autosize,我在LinearLayout中包含的DialogFragment中使用listview <?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="match_parent" android:orie
<?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="match_parent"
android:orientation="vertical"
android:padding="@dimen/dialog_main_margin" >
<com.modelmakertools.simplemind.DragSortListView
android:id="@+id/drag_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
为了找到问题的根源,我将listview的宽度和高度更改为固定的400dp(而不是匹配父/换行内容)。修正尺寸完全消除了问题。
因此,我的问题是:是否有一种方法可以避免对话框片段在布局一次后调整其大小?我找到了一种方法来阻止listview使用下面的代码更新对话框大小。 然而,事实证明,这只解决了部分问题:在列表“固定”之前,加载仍然非常缓慢。但这还有另一个原因,超出了这个问题/答案的范围
@Override
public void onResume() {
super.onResume();
// Fixate the listview height once the listview has been measured rather than keeping it at "wrap_content"
// This drastically improves rearrange performance.
if (_listView != null) {
_listView.postDelayed(new Runnable() {
@Override
public void run() {
fixateListViewHeight();
}
}, 500);
}
}
private void fixateListViewHeight() {
if (_listView != null) {
int h = _listView.getMeasuredHeight();
if (h != 0) {
LayoutParams params = (LayoutParams) _listView.getLayoutParams();
if (params != null)
params.height = h;
}
}
}
在使用对话框片段的活动的
AndroidManifest.xml
中,尝试将windowSoftInputMode
属性设置为adjustNothing
<activity
...
android:windowSoftInputMode="adjustNothing">
...
...
这不起作用,因为我需要进行初始调整以自动调整对话框大小。此外,它将禁用所有其他对话框的自动调整大小。此调整适用于软键盘,然后在显示时它将与当前视图重叠。啊,我无法使用此功能,因为我需要软键盘来缩小“活动内容”视图。
<activity
...
android:windowSoftInputMode="adjustNothing">
...