Search code examples
androidandroid-progressbarandroid-scrollbar

Scrollable progress bar


I'm trying making a scrollable horizontal progress bar.

Therefore I put the progress bar in Horizontal scroll view and set progress bar min width to 1000 (it's double my screen width).

But I still can't scroll the scroll bar...

The XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.pkg.pkg2.scrollableprogressbar.MainActivity">

    <HorizontalScrollView
        android:layout_width="1000dp"
        android:layout_height="wrap_content"
        android:measureAllChildren="true"
        android:background="#e3ece5">

        <ProgressBar
            style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="visible"
            android:id="@+id/progressBar"
            android:progress="50"
            android:minWidth="1000dp"/>
    </HorizontalScrollView>
</LinearLayout>

What can I try next?


Solution

  • I tried your solution with one changes, assign width of horizontalscrollview to wrap_content.
    Here is my layout

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <HorizontalScrollView
            android:layout_width="wrap_content"
            android:scrollbars="horizontal"
            android:layout_height="wrap_content">
    
            <ProgressBar
                style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Horizontal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:visibility="visible"
                android:id="@+id/progressBar"
                android:progress="50"
                android:secondaryProgress="100"
                android:minWidth="1000dp"
                android:focusable="false"
                android:nestedScrollingEnabled="false" />
        </HorizontalScrollView>
    
    </LinearLayout>