android - 搜索栏拇指中心不在起点

标签 android seekbar

enter image description here

作为我的图片,搜索栏进度=0,但搜索栏拇指中心不在起点。我的代码:

   <SeekBar  android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:progressDrawable="@drawable/seekbar_progress"
                 android:thumb="@drawable/seekbarthumb"
                 android:minHeight="10dip"
                 android:maxHeight="10dip"
                 android:thumbOffset="0px"
                 android:max="100"
                 android:id="@+id/bright_seekbar"
                 android:layout_marginLeft="60dip"/>

seekbar_progress

 <?xml version="1.0" encoding="utf-8"?>
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:id="@android:id/background"> 
    <shape> 
        <corners android:radius="5dip" /> 
        <gradient 
                android:startColor="#ff9d9e9d" 
                android:centerColor="#ff5a5d5a" 
                android:centerY="0.75" 
                android:endColor="#ff747674" 
                android:angle="270" 
        /> 
    </shape> 
</item> 
<item android:id="@android:id/secondaryProgress"> 
    <clip> 
        <shape> 
            <corners android:radius="5dip" /> 
            <gradient 
                    android:startColor="#80ffd300" 
                    android:centerColor="#80ffb600" 
                    android:centerY="0.75" 
                    android:endColor="#a0ffcb00" 
                    android:angle="270" 
            /> 
        </shape> 
    </clip> 
</item> 
<item android:id="@android:id/progress"> 
    <clip> 
        <shape> 
            <corners android:radius="5dip" /> 
            <gradient 
                    android:startColor="#FFD700" 
                    android:centerColor="#FFB90F" 
                    android:centerY="0.75" 
                    android:endColor="#FFA500" 
                    android:angle="270" 
            /> 
        </shape> 
    </clip> 
 </item> 


</layer-list>

seekbarthumb.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" 
      android:drawable="@drawable/pressed_button__volume" />
<item android:state_focused="true" 
      android:drawable="@drawable/pressed_button__volume" />
<item
     android:drawable="@drawable/default_button__volume" />     
</selector>

default_button__volume 是图片

最佳答案

终于找到了答案,这里的情况是 android:thumbOffset NOT thumb place 和 progress bar 的 setter ,但是,它是拇指长度 开始它的中心点,以便seekbar可以调整拇指的中心点在它的起点。因此,如果我们有一个 width50 的缩略图,则 thumbOffset 必须为 25(50/2), 这样 seekbar 就会调整 pixel 25 处的 zero value 使拇指看起来正好在中间。 感谢that man谁重定向我知道这一点。

关于android - 搜索栏拇指中心不在起点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18995680/

相关文章:

安卓自定义 map

java - 如何查明某些代码是否与某个 Android API 级别兼容

Android:停止将应用程序带入前台的新 Activity

android - 如何在搜索栏中设置双值

android - 选择多个联系人的示例项目

java - 使用 SeekBar 更新 Android 布局中的计算值

Android seekbar thumb drawable 显示不正确

android - 显示搜索栏的进度

android - 禁用客户端对搜索栏的更改

android - 如何为小米、红米、三星、华为等创建Android虚拟设备AVD