问题
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.
but under support lib 23.1.0, whether I set how much of padding, SeekBar and AppCompatSeekBar has no any change, like following screenshot.
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'
}
回答1:
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);
// ...
}
回答2:
Set this attributes in XML
android:paddingStart="0dp"
回答3:
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.
回答4:
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
回答5:
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
来源:https://stackoverflow.com/questions/33473849/android-seekbar-cant-be-full-width-even-set-padding-0-in-appcompat-23-1-0