如果我在SeekBar
中设置了draw“progress drawable”,我会在所有进度行中获得bgdraw。如何从开始到拇指位置设置绘图?
答案 0 :(得分:8)
你可以这样使用:
在可绘制文件夹中制作自定义文件....
<?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="#00000000"
android:centerColor="#00000000"
android:centerX="1"
android:endColor="#00000000"
android:angle="0"
/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress" >
<clip android:clipOrientation="horizontal" android:gravity="left" >
<shape>
<gradient
android:startColor="@color/blue"
android:centerColor="@color/blue"
android:centerX="0.75"
android:endColor="@color/blue"
android:angle="0"
/>
</shape>
</clip>
</item>
<item android:id="@android:id/progress" >
<clip android:clipOrientation="horizontal" android:gravity="left" >
<shape>
<gradient
android:startColor="@color/blue"
android:centerColor="@color/blue"
android:centerX="0.75"
android:endColor="@color/blue"
android:angle="0"
/>
</shape>
</clip>
</item>
然后在xml文件中设置此自定义文件:
<SeekBar
android:id="@+id/skProgress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="@android:color/white"
android:gravity="center|center_vertical"
android:progressDrawable="@drawable/progress_Ever" // here whatever name your custom file in drawable...set to here
/>
答案 1 :(得分:4)
在您的xml中
<SeekBar
android:id="@+id/skProgress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="@android:color/white"
android:gravity="center|center_vertical"
android:progressDrawable="@drawable/progress_drawable"
/>
progress_drawable.xml
将此xml放入Drawable文件夹
<?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="#00000000"
android:centerColor="#00000000"
android:centerX="1"
android:endColor="#00000000"
android:angle="0"
/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress" >
<clip android:clipOrientation="horizontal" android:gravity="left" >
<shape>
<gradient
android:startColor="@color/blue"
android:centerColor="@color/blue"
android:centerX="0.75"
android:endColor="@color/blue"
android:angle="0"
/>
</shape>
</clip>
</item>
<item android:id="@android:id/progress" >
<clip android:clipOrientation="horizontal" android:gravity="left" >
<shape>
<gradient
android:startColor="@color/blue"
android:centerColor="@color/blue"
android:centerX="0.75"
android:endColor="@color/blue"
android:angle="0"
/>
</shape>
</clip>
</item>
</layer-list>
答案 2 :(得分:1)
在你的xml中放这个
<SeekBar
.....
android:background="@null"
android:splitTrack="false"
android:progressDrawable="@drawable/progress_drawable"
/>
并在您的seek_bar_progress drawable中留空背景部分,但将渐变部分放入剪辑标记。
<item android:id="@android:id/secondaryProgress" >
<clip android:clipOrientation="horizontal" android:gravity="left" >
<shape>
<gradient
android:startColor="@color/blue"
android:centerColor="@color/blue"
android:centerX="0.75"
android:endColor="@color/blue"
android:angle="0"
/>
</shape>
</clip>
</item>