繁体   English   中英

通过编程设置宽度和高度时,Android ScrollView的滚动禁用

[英]Android ScrollView's scroll disable when set width & height programically

我的Android应用程序具有以下结构

LinearLayout
     ScrollView
          LinearLayout
           -- Elements ---

然后,我需要以编程方式设置ScrollView的宽度和高度。 所以我写了下面的代码

ScrollView sv=(ScrollView)activity.findViewById(R.id.menuScroll);
LinearLayout.LayoutParams relp=new LinearLayout.LayoutParams(width/2,height-margin);
relp.setMargins(width, 0, 0, 0);
sv.setLayoutParams(relp);

但是当我添加setLayoutParams ,它的scroll属性。 无法滚动内部元素。 任何想法 ? 我是Android新手。

谢谢

我将此用于RelativeLayout:

 private ScrollView mScrollView;
 mScrollView = (ScrollView) findViewById(R.id.scrollView);

 RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mScrollView.getLayoutParams();
 layoutParams.leftMargin= width;
 layoutParams.setMargins(width, 0, 0, 0);
 mScrollView.setLayoutParams(layoutParams);

这对我有用。 我认为这类似于LinearLayout。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM