且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

滚动型向下滚动视图的大小发生变化时

更新时间:2023-12-03 09:46:04

我觉得这个步骤,你可以做到这一点:


  • 创建,从滚动视图扩展自定义滚动视图

  • 定义一个布尔属性启用和禁用滚动

  • 检查的onScollChanged方法的布尔变量,如果是真的返回false

  • 将布尔变量真正加入动态视图到它的容器之前

  • 设置为false添加完成后

我希望这些帮助你。

I currently have a ScrollView with a LinearLayout. I'm changing some content dynamically, e.g. setting a long text passage dynamically, and adding dynamic layouts (buttons etc.). This causes the linear layout's height to change, which causes the ScrollView to scroll down. How can I keep the current scroll position while the layout is being dynamically updated?

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical
        android:gravity="center_horizontal"
        >

        <!-- Dynamic Content Here -->
    </LinearLayout>
</ScrollView>

I think with this steps you can do it :

  • Create a custom scroll view that extends from scrollview
  • Define a boolean property for enabling and disabling scroll
  • Check the boolean variable on the onScollChanged method and return false if is true
  • Set the boolean variable true before adding dynamic views to it's container
  • Set it to false when adding done

I hope these help you