即使在 AppCompat 23.1.0 中设置填充 0,Android SeekBar 也不能全宽

标签 android android-support-library seekbar

当我将 android 支持库从 23.0.1 更新到 23.1.0 时,我发现 SeekBar 不再是全宽了。

这是测试 XML 文件:

<?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>

它在支持 lib 23.0.1 下运行良好,如下图所示。 SeekBar 有默认填充,当我手动设置 padding=0 时,它可以是全宽。并且 AppCompatSeekBar 还不存在。

enter image description here

但在支持lib 23.1.0下,无论我设置多少填充,SeekBar和AppCompatSeekBar都没有任何变化,如下图所示。

enter image description here

所以,这是支持库的错误,任何机构遇到这个问题以及如何解决它?

谢谢~!

更新:
这完全让我感到困惑,我刚刚进行了另一个测试,我创建了一个新项目,无论我使用 AppCompat 23.0.1 还是 23.1.0,设置 padding=0 后,SeekBar 都不能全宽,(compileSdkVersion 为 23,buildToolsVersion 为“23.0.1",targetSdkVersion 为 23)。无论如何,我想知道当设置 padding=0 不起作用时如何使 SeekBar 全宽。

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'
}

最佳答案

最后,我突然想到。为什么不尝试通过java代码修改它。有用!以下是示例代码:

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);

    // ...
}

关于即使在 AppCompat 23.1.0 中设置填充 0,Android SeekBar 也不能全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33473849/

相关文章:

android - 从服务器获取配置字符串

android - NoClassDefFoundError - AppCompatDelegateImplV14

android - 我需要使用 Android 支持库吗

android - 你如何实现底部有按钮的 snackbar ?

带有 SeekBar 的 Android - 防止 'thumb' 在触摸 SeekBar 以拖动/滚动屏幕时移动

android - 使用 Butterknife 的 OnSeekBarChangeListener

android - 如何以编程方式设置 Android SeekBar 进度可绘制

android - 使用 IAM 从 Android MQTT 客户端登录 AWS IoT 不起作用

android - RecyclerView 和 onClicklistener

android - Qt Creator Android 错误 "Platform SDK installed"