Android 1父级ScrollView,3垂直滚动的TextView

Android 1父级ScrollView,3垂直滚动的TextView,第1张

概述我对android编程有疑问.我有一个用于整个活动的父滚动视图,并且有三个具有滚动功能的文本视图.但是,当我使用以下代码时,它似乎根本无法工作.仅父级滚动可用.finalViewview=inflater.inflate(R.layout.activity_register_terms_fragment,container,false);

我对android编程有疑问.

我有一个用于整个活动的父滚动视图,并且有三个具有滚动功能的文本视图.但是,当我使用以下代码时,它似乎根本无法工作.仅父级滚动可用.

        final VIEw vIEw = inflater.inflate(R.layout.activity_register_terms_fragment, container, false);        TextVIEw basicTermVIEw = (TextVIEw) vIEw.findVIEwByID(R.ID.register_terms_basic_info);        TextVIEw purposeTermVIEw = (TextVIEw) vIEw.findVIEwByID(R.ID.register_terms_purpose_info);        TextVIEw provIDeTermVIEw = (TextVIEw) vIEw.findVIEwByID(R.ID.register_terms_provIDe_info);        TextVIEw prevIoUs = (TextVIEw) vIEw.findVIEwByID(R.ID.register_terms_pre);        TextVIEw next = (TextVIEw) vIEw.findVIEwByID(R.ID.register_terms_next);        basicTermVIEw.setMovementMethod(new ScrollingMovementMethod());        purposeTermVIEw.setMovementMethod(new ScrollingMovementMethod());        provIDeTermVIEw.setMovementMethod(new ScrollingMovementMethod());

我应该如何更改密码?
感谢你们对我的帮助!

解决方法:

ScrollVIEw内不能有可滚动的视图,例如TextVIEw或ListVIEw或RecyclerVIEw.因此,可以在常规布局中使用简单的TextVIEw并为其添加androID:scrollbars属性,也可以使用视图的自定义类,该类将以编程方式计算视图的宽度/高度,并使用ScrollVIEw作为其父级.

例如,要在滚动视图中使用ListvIEw,我们需要使用ListvIEw的以下自定义类,该类将计算列表项的高度并对其进行设置.

public class ExpandedListVIEw extends ListVIEw {private VIEwGroup.LayoutParams params;private int old_count = 0;public ExpandedListVIEw(Context context, AttributeSet attrs) {     super(context, attrs);}   public ExpandedListVIEw(Context context) {    super(context);}public ExpandedListVIEw(Context context, AttributeSet attrs, int defStyle) {    super(context, attrs, defStyle);}@OverrIDepublic voID onMeasure(int wIDthMeasureSpec, int heightmeasureSpec) {        int heightmeasureSpec_custom = MeasureSpec.makeMeasureSpec(                Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);        super.onMeasure(wIDthMeasureSpec, heightmeasureSpec_custom);        VIEwGroup.LayoutParams params = getLayoutParams();        params.height = getMeasuredHeight();    }@OverrIDeprotected voID onDraw(Canvas canvas) {    if (getCount() != old_count) {        this.setScrollContainer(false);        old_count = getCount();        params = getLayoutParams();        params.height = getCount()                * (old_count > 0 ? getChildAt(0).getHeight() : 0);        setLayoutParams(params);    }    super.onDraw(canvas);}}
总结

以上是内存溢出为你收集整理的Android 1父级ScrollView,3垂直滚动的TextView全部内容,希望文章能够帮你解决Android 1父级ScrollView,3垂直滚动的TextView所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1090179.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存