Android 设置ScrollView最大高度
- 首先定义一个实现类
public class OnViewGlobalLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener {
private int maxHeight = 500;
private View view;
public OnViewGlobalLayoutListener(View view, int height) {
this.view = view;
this.maxHeight = height;
}
@Override
public void onGlobalLayout() {
if (view.getHeight() > maxHeight)
view.getLayoutParams().height = maxHeight;
}
}
2.再在代码中调用即可
scrollView.getViewTreeObserver().addOnGlobalLayoutListener(new OnViewGlobalLayoutListener(scrollView, 700));
FlowLiver Notes

浙公网安备 33010602011771号