gpt4 book ai didi

Android - 如何更改默认 SeekBar 厚度?

转载 作者:IT老高 更新时间:2023-10-28 22:09:27 26 4
gpt4 key购买 nike

我有这个 SeekBar:

        <SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
android:id="@+id/seekbar"
android:visibility="gone"
android:maxHeight="3dp"/>

我已尝试使用 maxHeight 更改此 SeekBar 厚度。但什么都没有改变。它看起来像这样:

enter image description here

我想将此 SeekBar 的粗细更改为 3dp 并使其看起来像这样: enter image description here

所以我的问题是有可能以某种方式改变 SeekBar 的厚度吗?如果是,怎么做?

最佳答案

你必须改变 SeekBarprogressDrawablethumb 来调整它的粗细:

<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/indSeekBar"
android:layout_marginTop="48dp"
android:progressDrawable="@drawable/seek_bar"
android:thumb="@drawable/seek_thumb"
/>

添加到drawable文件夹seek_bar.xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape
android:shape="line">
<stroke
android:color="@color/seek_bar_background"
android:width="@dimen/seek_bar_thickness"/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape
android:shape="line">
<stroke
android:color="@color/seek_bar_secondary_progress"
android:width="@dimen/seek_bar_thickness"/>
</shape>
</clip>
</item>

<item android:id="@android:id/progress">
<clip>
<shape
android:shape="line">
<stroke
android:color="@color/seek_bar_progress"
android:width="@dimen/seek_bar_thickness"/>
</shape>
</clip>
</item>

</layer-list>

seek_thumb.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:height="@dimen/seek_bar_thumb_size"
android:width="@dimen/seek_bar_thumb_size"
/>
<solid android:color="@color/seek_bar_progress"/>
</shape>

添加到尺寸资源(更改此项以调整厚度):

<dimen name="seek_bar_thickness">4dp</dimen>
<dimen name="seek_bar_thumb_size">20dp</dimen>

添加颜色资源:

<color name="seek_bar_background">#ababab</color>
<color name="seek_bar_progress">#ffb600</color>
<color name="seek_bar_secondary_progress">#3399CC</color>

enter image description here

关于Android - 如何更改默认 SeekBar 厚度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32212259/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com