在运行时列出行高
List row height at runtime
在执行时确定 ListView[= 的第一个 cell 的 height 的正确方法是什么? 16=]?该列表充满了 HTTP 请求的结果,并且列表行布局的高度为“wrap_content”。我需要那个高度才能将其设置为另一个视图。
在为位置 0 生成视图时检查适配器中的高度
同样重要的是要注意何时进行测量。
您需要在计算布局后执行此操作。您可以在 onCreate 中尝试这样的操作:
// add global layout listener on root view of your fragment
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
yourcell.measure()... // DO the measurement here...
}
}
cell.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
这种方法行得通,谁能解释一下为什么? :)
在执行时确定 ListView[= 的第一个 cell 的 height 的正确方法是什么? 16=]?该列表充满了 HTTP 请求的结果,并且列表行布局的高度为“wrap_content”。我需要那个高度才能将其设置为另一个视图。
在为位置 0 生成视图时检查适配器中的高度
同样重要的是要注意何时进行测量。 您需要在计算布局后执行此操作。您可以在 onCreate 中尝试这样的操作:
// add global layout listener on root view of your fragment
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
yourcell.measure()... // DO the measurement here...
}
}
cell.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
这种方法行得通,谁能解释一下为什么? :)