Android SeekBar can't be full width even set padding 0 in AppCompat 23.1.0
Asked Answered
G

7

29

when I update android support lib from 23.0.1 to 23.1.0, I find the SeekBar is not full width any more.

this is the test XML file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:divider="@drawable/space_divider"
    android:orientation="vertical"
    android:padding="8dp"
    android:showDividers="middle">

    <View
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:background="@android:color/black"/>

    <!-- default SeekBar -->
    <SeekBar
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:progress="50"
        android:progressTint="@android:color/holo_red_dark"/>

    <!-- padding=0 -->
    <SeekBar
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:padding="0dp"
        android:progress="50"
        android:progressTint="@android:color/holo_red_dark"/>

    <!-- padding=40 -->
    <SeekBar
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:padding="40dp"
        android:progress="50"
        android:progressTint="@android:color/holo_red_dark"/>

    <android.support.v7.widget.AppCompatSeekBar
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:padding="0dp"
        android:progress="50"/>

</LinearLayout>

It works well under support lib 23.0.1, like following screenshot. SeekBar has default padding, when I set padding=0 manual, it can be full width. and AppCompatSeekBar is not exist yet.

enter image description here

but under support lib 23.1.0, whether I set how much of padding, SeekBar and AppCompatSeekBar has no any change, like following screenshot.

enter image description here

so, is this the bug of support lib, any body meet this problem and how to resolve it?

thank you~!

update:
It totally confused me, I just have another test, I create a new project, whether I use AppCompat 23.0.1 or 23.1.0, SeekBar neither can be full width after set padding=0, (the compileSdkVersion is 23, buildToolsVersion is "23.0.1", targetSdkVersion is 23). anyway, I want to know how to make SeekBar full width when set padding=0 not work.

the build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.test.seekbar"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.1'
}
Gaspard answered 2/11, 2015 at 8:54 Comment(0)
G
39

finally, I just have a sudden thought. why not try modify it by java code. It works! following is the sample code:

protected void initViews(Context context) {
    LayoutInflater.from(context).inflate(getLayoutResId(), this);
    ButterKnife.bind(this);

    // set style, just once
    seekBar.setProgress(0);
    seekBar.setMax(0);

    seekBar.setPadding(0, 0, 0, 0);

    // ...
}
Gaspard answered 2/11, 2015 at 10:16 Comment(6)
ohh.. Guy!! I've tried android:padding="0dp" in style and in view xml and this hasn't helped. Thank you!Cleome
It works but does any know what's actually going on and why this happens ?Myself
We can't get equi-efficacious thereby setting the padding in XML?Gorgon
This is it. Thanks. Ya you just need to override the default padding.Contradictory
Setting to 0dp will clip the thumb when in the outer positions. To handle that add android:clipChildren="false" in the parent view.Gratuitous
This does not work for me even also with android:paddingt="0dp" in the layout.Darfur
H
34

Set this attributes in XML

android:paddingStart="0dp" 
Heda answered 20/3, 2017 at 9:45 Comment(1)
Maybe android:paddingEnd="0dp" for the other side.Portuguese
C
28

Try adding the parameters paddingStart and paddingEnd to 0dp in the xml file. If your app is compatible with Rtl you will need to add those in order to visualize the seekBar with no padding otherwise it will show with padding even if using it in a Ltr language.

Cacodyl answered 5/8, 2016 at 4:13 Comment(3)
However, be aware that padding set to 0dp will clip the thumb when in the outer positions (for instance when the seekbar is taking up the entire width of the screen).Jerz
Good call out Anton. To address this add android:clipChildren="false" in the parent view.Gratuitous
I use this android:thumbOffset=0dp will not clip the thumbClabo
H
5

Try this

android:paddingStart="0dp"
android:paddingEnd="0dp"
Hemimorphite answered 4/4, 2021 at 15:44 Comment(1)
This does not work for me, and not even android:paddingt="0dp".Darfur
R
3

As Didac mentioned you can set the padding to 0 in xml.

But make sure you set the padding after you set the progressTint or progressDrawable.

I had a similar problem (where I was setting progressDrawable). Once I set the padding as 0 after setting the progressDrawable, the seekbar padding has gone

Revelationist answered 16/9, 2016 at 18:37 Comment(0)
D
2

if you seekBar.setPadding(0, 0, 0, 0); may be the thumb can't show complete。 First, you should find what result this. In fact, in the seek bar style, you can find this.

<style name="Base.Widget.AppCompat.SeekBar" parent="android:Widget">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:progressDrawable">@drawable/abc_seekbar_track_material</item>
    <item name="android:indeterminateDrawable">@drawable/abc_seekbar_track_material</item>
    <item name="android:thumb">@drawable/abc_seekbar_thumb_material</item>
    <item name="android:focusable">true</item>
    <item name="android:paddingLeft">16dip</item>
    <item name="android:paddingRight">16dip</item>
</style>

so change the style with paddingLeft and paddingRight

Dryclean answered 21/2, 2019 at 2:51 Comment(0)
S
0

You can set padding to 0, but then you need to android:clipChildren="false" on the container layout. Or you can use negative margins on the SeekBar.

Shalandashale answered 11/7, 2022 at 11:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.