Azizjon Kholmatov
Azizjon Kholmatov

Reputation: 1256

Disabling scrolling after specific child

In my case, I have a HorizontalScrollView. What I need to achieve is that HorizontalScrollView should be scollable until a specific child. (By child I mean view lying inside HorizontalScrollView.) User should not be able to scroll the rest of it. My current minimum SDK is 21. So that I cannot use HorizontalScrollView.setOnScrollChange() method. It is available for API level 23+.

Searched the net for some time but could not find solutions suitable for my case.

How can I achieve this? Any suggestions would greatly help.

The reason for doing this is to achieve an affect where scrollbar stops from scrolling at a specified location. See the picture below. enter image description here

Upvotes: 0

Views: 72

Answers (1)

Rafael T
Rafael T

Reputation: 15679

You can kind of fake the sugested behaviour by adding a ScrollView which fills up half the screen and adding static elements right next to it.

below is a pseudo layout on how it can be done:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1">
    <ScrollView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".5">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#FF0000">

            <!-- Scrollable Items here -->
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="item1"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="item2"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="item3"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:text="item4"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:text="item5"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:text="item6"/>
        </LinearLayout>
    </ScrollView>
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".5"
        android:orientation="horizontal"
        android:background="#00FF00">
        <!-- Unscrollable Items here -->
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="item1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="item2"/>


    </LinearLayout>

</LinearLayout>

the important part is weightSum=1 and the layout_weights of .5 with a respective width of 0 . You can adjust them to your needs of course.

Upvotes: 1

Related Questions