我在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: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>其中DragSortListView基于第三方ListView后代,允许使用拖拽手柄图像重新排列项目。
当此代码在(全屏)活动中使用时,一切正常,但当在android.support.v4.app.DialogFragment中使用时,拖动项目会导致对话框+列表视图组合继续更新对话框大小。这会导致拖动非常慢,并且我看到了很多LogCat消息:
06-06 15:37:07.833: I/Choreographer(17281): Skipped 166 frames! The application may be doing too much work on its main thread.为了定位问题的根源,我将列表视图的宽度和高度更改为固定的400dp (而不是match_parent / wrap_content)。修复大小可以完全消除该问题。因此,我的问题是:有没有一种方法可以避免对话框片段在布局一次后调整其大小?
发布于 2013-06-10 14:43:22
我用下面的代码找到了一种停止列表视图更新对话框大小的方法。然而,事实证明,这只解决了问题的一部分:在列表被“固定”之前,加载仍然非常慢。但这还有另一个原因,超出了这个问题/答案的范围。
@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;
}
}
}发布于 2013-06-26 07:25:48
尝试在使用对话框片段的活动的AndroidManifest.xml中将windowSoftInputMode属性设置为adjustNothing。
<activity
...
android:windowSoftInputMode="adjustNothing">
...https://stackoverflow.com/questions/16964259
复制相似问题