我在下面的代码中使用新高度来滚动视图
但不工作
viewFindPos = (ScrollView) findViewById(R.id.Roll);
viewFindPos.getLayoutParams().height = 5000;
// OR : viewFindPos.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 5000));
答案 0 :(得分:0)
获取ScrollView的Layout参数后,需要将LayoutParameters设置回View。稍后请求布局,因此重新绘制。请查看下面的代码,这将有助于您理解。
LayoutParams params = viewFindPos.getLayoutParams();
params.height = 5000;
viewFindPos.setLayoutParams(params);
viewFindPos.requestLayout();
答案 1 :(得分:0)
这有效:
@覆盖
public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); ScrollView viewFindPos =(ScrollView)findViewById(R.id.scrollView); viewFindPos.getLayoutParams()。height = 500; } OR
@覆盖
protected void onResume()
{
super.onResume(hasFocus);
ScrollView viewFindPos = (ScrollView) findViewById(R.id.scrollView);
viewFindPos.getLayoutParams().height = 100;
}