You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android如何让SeekBar更粗?已尝试常见方案仍未解决

问题:垂直SeekBar无法填满父布局空间

我使用Android Studio和Kotlin开发,custom_lvlmeter_channel.xml的FrameLayout内包含一个通过旋转270°实现的垂直SeekBar,目标是制作一个无滑块的粗SeekBar并让它填满可用空间。但目前SeekBar到一定宽度后不再变宽,剩余区域显示蓝色背景。


相关代码

custom_lvlmeter_channel.xml

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout android:id="@+id/flSeekbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#59A2DC"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <com.example.levelmeter.widgetlogic.LevelMeterChannel
        android:id="@+id/sbFader"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:progress="10"
        android:progressDrawable="@drawable/draw_custom_lvlmeter_channel"
        android:rotation="270"
        android:thumb="@null"
        />

</FrameLayout>

drawable/draw_custom_lvlmeter_channel.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>
            <gradient
                android:startColor="#ffe9e9e9"
                android:centerColor="#ffc6c6c6"
                android:centerY="0.75"
                android:endColor="#ffe9e9e9"
                android:angle="270"/>

        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <gradient
                    android:startColor="#ffe9e9e9"
                    android:endColor="#ff2165ca"
                    android:angle="270" />
            </shape>
        </clip>
    </item>
</layer-list>

LevelMeterChannel.kt

package com.example.levelmeter.widgetlogic

import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatSeekBar

class LevelMeterChannel(context: Context, attrs: AttributeSet) : AppCompatSeekBar(context, attrs) {


    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(heightMeasureSpec, heightMeasureSpec)
    }
}

已尝试的解决方案(均未解决问题,仅改变了SeekBar颜色)

  • 尝试了创建宽SeekBar的相关方案
  • 尝试了YouTube上的相关教程

内容的提问来源于stack exchange,提问作者MaDudeeK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 12:35:19