关于自定义SeekBar写法以及seekbar不显示的问题

来源:互联网 发布:淘宝手机充值软件利润 编辑:程序博客网 时间:2024/05/16 18:55

最近写seekbar的时候突然遇到一个问题,就是内容都设置好了但是就是不显示,界面上空空的,初始代码如下

<SeekBar                android:id="@+id/playbar_sb_quick_player_bar"                style="@style/seekbar_style"                android:layout_width="match_parent"                android:layout_height="6dp"/>

style文件seekbar_style布局如下,thumb是seekbar的滑块,因为滑块会被覆盖一部分,thumbOffset是设置滑块的左边距,使其不被覆盖

<style name="seekbar_style" parent="@android:style/Widget.SeekBar">        <item name="android:indeterminateOnly">false</item>        <item name="android:minHeight">@dimen/y6</item>        <item name="android:maxHeight">@dimen/y6</item>        <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>        <item name="android:progressDrawable">@drawable/seekbar_horizontal</item>        <item name="android:thumb">@drawable/f_playing_point</item>        <item name="android:thumbOffset">2.0dp</item>    </style>

其中seekbar_horizontal.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"        android:drawable="@drawable/bg">    </item>    <item android:id="@android:id/secondaryProgress">        <clip>            <shape>                <corners android:radius="2.0dip"/>                <gradient                    android:angle="270.0"                    android:centerColor="#a5a5a5"                    android:centerY="0.5"                    android:endColor="#a5a5a5"                    android:startColor="#a5a5a5"/>            </shape>        </clip>    </item>    <item android:id="@android:id/progress">        <clip>            <shape>                <corners android:radius="2.0dip"/>                <gradient                    android:angle="270.0"                    android:centerColor="#fa8100"                    android:centerY="0.5"                    android:endColor="#fa8100"                    android:startColor="#fa8100"                />            </shape>        </clip>    </item></layer-list>


此处的gra是渐变的shape,startColor,centerColor,endColor分别是初始,中间,结束颜色,此处为了方便都设置为一种颜色

至此,自定义seekbar圆满结束,但是运行的时候发现seekbar没有显示

排查发现是因为seekbar的height设置了具体的大小6dp导致的,应该是

<SeekBar                style="@style/seekbar_style"                android:layout_width="match_parent"                android:layout_height="wrap_content"/>

解决问题



1 0