即使在AppCompat 23.1.0中将padding设置为0,Android SeekBar也无法全角显示 [英] Android SeekBar can't be full width even set padding 0 in AppCompat 23.1.0

查看:59
本文介绍了即使在AppCompat 23.1.0中将padding设置为0,Android SeekBar也无法全角显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将android support lib从23.0.1更新到23.1.0时,我发现SeekBar不再是全角了.

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

这是测试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设置为manual时,它可以是全角.和AppCompatSeekBar还不存在.

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.

但是在支持lib 23.1.0的支持下,无论我设置多少填充,SeekBar和AppCompatSeekBar都没有任何变化,如以下屏幕截图所示.

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

那么,这是支持lib的错误吗,任何机构都遇到此问题以及如何解决?

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

谢谢〜!

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

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.

build.gradle:

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

推荐答案

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

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

    // ...
}

这篇关于即使在AppCompat 23.1.0中将padding设置为0,Android SeekBar也无法全角显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆