Creating a locked ScrollView in Android

Viewed 1606

I'm trying to implement a ScrollView in Android that doesn't scroll when adding an item above the current scroll position.

The default implementation of ScrollView behaves as following:

Adding an item above the current scroll position: enter image description here

Adding an item below the current scroll position: enter image description here

How can I "lock" the ScrollView prior to adding an item above the current scroll position?

This is my layout file, I've currently overridden both the ScrollView and LinearLayout, but haven't made any alterations yet.

<LinearLayout
      android:layout_height="fill_parent"
      android:orientation="vertical"
      android:layout_width="fill_parent">

    <LinearLayout
        android:id="@+id/LinearLayout02"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_alignParentBottom="true">
        <Button
            android:id="@+id/Button02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" android:text="Add To Top"
            android:onClick="addToStart">
        </Button>
        <Button
            android:id="@+id/Button03"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Add to End"
            android:onClick="addToEnd">
        </Button>
    </LinearLayout>
    <com.poc.scroller.locable.lockablescrollerpoc.LockedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        android:verticalScrollbarPosition="right"
        android:fadeScrollbars="false"
        android:background="@color/scrollColor">

        <com.poc.scroller.locable.lockablescrollerpoc.LockedLinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/Container">
        </com.poc.scroller.locable.lockablescrollerpoc.LockedLinearLayout>

    </com.poc.scroller.locable.lockablescrollerpoc.LockedScrollView>
</LinearLayout>
</android.support.constraint.ConstraintLayout>

Example Source Code: https://github.com/Amaros90/android-lockable-scroller-poc

Thank you!

4 Answers
Related