Android SeekBar 自动更改大小并偏移 "thumb" 所以没有正确排列
Android SeekBar automatically changes size and offsets the "thumb" so nothing lines up correctly
所以我正在尝试创建自定义 SeekBar。在我认为我想要的东西可以通过 ProgressBar 实现之前,所以当我将它作为进度条时它工作正常,我能够使用自定义可绘制对象根据需要更改颜色。当我需要合并 "thumb".
时,问题就出现了
在我将 ProgressBar 更改为 SeekBar 之后,seekbar "shrinks" 立即不再适合轮廓。第一张图片显示搜索栏不适合尺寸...
这张图片是我正在尝试完成的示例...
您可能还注意到我那里的白色 "gap/thumb" 没有与正确的位置(彩色绘图结束的地方)对齐
我怀疑这与正在发生的无法解释的萎缩有关?
注意: 当我将 SeekBar 的填充设置为 0 时,视图会恢复到正确的尺寸,但是 "thumb" 仍然偏移,我认为这与间距有关......
这是 SeekBar
的 XML
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/imageView1"
android:orientation="vertical"
android:paddingLeft="4dp"
android:paddingRight="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<SeekBar
android:id="@+id/call_status_progress"
android:layout_width="match_parent"
android:layout_height="7dp"
android:focusable="false"
android:layout_marginTop="3dp"
android:progressDrawable="@drawable/status_waiting_drawable"
android:thumb="@drawable/seeker"
android:progress="1"
android:max="6"
android:indeterminate="false" />
</LinearLayout>
...
</LinearLayout>
这里是背景可绘制对象的XML
<?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="2px" />
<gradient
android:startColor="#D8D8D8"
android:centerColor="#D8D8D8"
android:centerY="0.75"
android:endColor="#D8D8D8"
android:angle="270"
/>
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="2px" />
<gradient
android:startColor="@color/status_waiting"
android:centerColor="@color/status_waiting"
android:centerY="0.75"
android:endColor="@color/status_waiting"
android:angle="270"
/>
</shape>
</clip>
</item>
找了半天终于找到答案了,这些不明显的错误通常都是简单的错误或忽略的属性。
对我来说,我的解决方案是设置属性
android:thumbOffset
android:thumbOffset="0dp"
我希望这个解决方案对以后的其他人有所帮助。
所以我正在尝试创建自定义 SeekBar。在我认为我想要的东西可以通过 ProgressBar 实现之前,所以当我将它作为进度条时它工作正常,我能够使用自定义可绘制对象根据需要更改颜色。当我需要合并 "thumb".
时,问题就出现了在我将 ProgressBar 更改为 SeekBar 之后,seekbar "shrinks" 立即不再适合轮廓。第一张图片显示搜索栏不适合尺寸...
这张图片是我正在尝试完成的示例...
您可能还注意到我那里的白色 "gap/thumb" 没有与正确的位置(彩色绘图结束的地方)对齐 我怀疑这与正在发生的无法解释的萎缩有关?
注意: 当我将 SeekBar 的填充设置为 0 时,视图会恢复到正确的尺寸,但是 "thumb" 仍然偏移,我认为这与间距有关......
这是 SeekBar
的 XML<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/imageView1"
android:orientation="vertical"
android:paddingLeft="4dp"
android:paddingRight="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<SeekBar
android:id="@+id/call_status_progress"
android:layout_width="match_parent"
android:layout_height="7dp"
android:focusable="false"
android:layout_marginTop="3dp"
android:progressDrawable="@drawable/status_waiting_drawable"
android:thumb="@drawable/seeker"
android:progress="1"
android:max="6"
android:indeterminate="false" />
</LinearLayout>
...
</LinearLayout>
这里是背景可绘制对象的XML
<?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="2px" />
<gradient
android:startColor="#D8D8D8"
android:centerColor="#D8D8D8"
android:centerY="0.75"
android:endColor="#D8D8D8"
android:angle="270"
/>
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="2px" />
<gradient
android:startColor="@color/status_waiting"
android:centerColor="@color/status_waiting"
android:centerY="0.75"
android:endColor="@color/status_waiting"
android:angle="270"
/>
</shape>
</clip>
</item>
找了半天终于找到答案了,这些不明显的错误通常都是简单的错误或忽略的属性。
对我来说,我的解决方案是设置属性 android:thumbOffset
android:thumbOffset="0dp"
我希望这个解决方案对以后的其他人有所帮助。