简体   繁体   English

我如何在Android的seekbar中绘制可绘制的进度

[英]How can l draw progress drawable in seekbar in android

If I set draw "progress drawable" in SeekBar I get bgdraw in all progress line. 如果我在SeekBar中将绘制设置为“ progress drawable”,则所有进度行中都会出现bgdraw。 How can I set draw from start to thumb position? 如何设置从开始到拇指位置的绘制?

you can use this way: 您可以使用这种方式:

make a custom file in drawable folder.... 在可绘制文件夹中创建自定义文件...。

<?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>

and after that set this custom file in your xml file: 然后在您的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
  />

In your xml 在您的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 progress_drawable.xml

put this xml in Drawable folder 将此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>

In your xml put this 在你的xml中

<SeekBar  
        .....               
        android:background="@null"
        android:splitTrack="false"
        android:progressDrawable="@drawable/progress_drawable"
 />

and in your seek_bar_progress drawable leave blank the background part but put your gradient part with clip tag. 在您的seek_bar_progress可绘制对象中,将背景部分留为空白,但将渐变部分与剪贴标签放在一起。

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM