2

I have implemented a simple SeekBar whose thumb gets large while the user touches it. While this works fine in Marshmallow devices, it doesn't on Lollipop.

In Marshmallow- (This is how it should be)
Default thumb- Appears correctly
On touch-
Enlarged thumb- Appears correctly

In Lollipop- (This is wrong)
enter image description here

The two problems are-

  1. The thumb is no longer vertically centered.
  2. The progress doesn't visibly change while the user is touching the thumb.

Here is my activity layout-

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipChildren="false">

        <SeekBar
            android:id="@+id/seekBar_main_green"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_marginTop="20dp"
            android:max="255"
            android:thumb="@drawable/custom_thumb_green" />

    </RelativeLayout>
</ScrollView>

Here is my class-

sbGreen.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // Changing background color of some other view
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            sbGreen.setThumb(ContextCompat.getDrawable(MainActivity.this, R.drawable.custom_thumb_green_large));
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            sbGreen.setThumb(ContextCompat.getDrawable(MainActivity.this, R.drawable.custom_thumb_green));
        }
    });

Here are my drawables-
custom_thumb-

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:bottom="10dp"
        android:left="10dp"
        android:right="10dp"
        android:top="10dp" >

        <shape android:shape="oval">
            <size
                android:width="10dp"
                android:height="10dp" />
            <solid android:color="#00af00" />
        </shape>
    </item>

    <item>
        <shape android:shape="oval">
            <solid android:color="#50008000"/>
            <size android:height="20dp" android:width="20dp"/>
        </shape>
    </item>
</layer-list>

custom_thumb_large-

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:bottom="30dp"
        android:left="30dp"
        android:right="30dp"
        android:top="30dp" >

        <shape android:shape="oval">
            <size
                android:width="10dp"
                android:height="10dp" />
            <solid android:color="#00af00" />
        </shape>
    </item>

    <item>
        <shape android:shape="oval">
            <solid android:color="#50008000"/>
            <size android:height="40dp" android:width="40dp"/>
        </shape>
    </item>
</layer-list>

Things I have tried-

Any help or suggestions are most welcome.

Community
  • 1
  • 1
H. Saxena
  • 335
  • 4
  • 11

0 Answers0