Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android中seekbar的自定义拇指_Android_Seekbar_Custom Selectors - Fatal编程技术网

Android中seekbar的自定义拇指

Android中seekbar的自定义拇指,android,seekbar,custom-selectors,Android,Seekbar,Custom Selectors,我想为seekbar创建一个自定义拇指,如下所示: 一种解决方案是,使用png图片绘制拇指 我认为应该可以只使用xml,因为它非常类似于: thumb.xml <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <size android:height="30dp" android:width="30dp"/> <s

我想为seekbar创建一个自定义拇指,如下所示:

一种解决方案是,使用png图片绘制拇指

我认为应该可以只使用xml,因为它非常类似于:

thumb.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <size android:height="30dp" android:width="30dp"/>
    <stroke android:width="18dp" android:color="#882EA5DE"/>
    <solid android:color="#2EA5DE" />
    <corners android:radius="1dp" />

</shape>

只需要添加第二个边框(周围的白色笔划),这样我就可以跳过以不同屏幕分辨率(hdpi/mdpi/xhdpi/xxhdpi)管理所有这些图片


我尝试了不同形状的“椭圆形”和“环形”组合,但未能获得所需的结果。您如何做到这一点?

我无法找到仅使用xml的解决方案,这就是我使用图片解决此问题的原因,需要以下方面的帮助:

  • 创建了拇指图标的图像
    seekbar\u thumb\u icon.png
    ,并将其以不同分辨率保存在
    res/drawable-*
    地图(hdpi/mdpi/xhdpi/xxhdpi)中

  • 为seekbar指定了“android:thumb=“@layout/seekbar\u thumb”:

  • <layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <item>
    <shape>
        <size
            android:height="30dp"
            android:width="30dp" />
    
        <solid android:color="@android:color/transparent" />
    </shape>
    </item>
    <item android:drawable="@drawable/balance_icon_48px"/>
    
    </layer-list>
    
    
    

    其他款式:

    <SeekBar
    android:id="@+id/seekbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:progressDrawable="@layout/seekbar_style"
    android:thumb="@layout/seekbar_thumb" />
    
    
    
    seekbar_style.xml

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent"
        android:layout_width="match_parent">
    
        <item android:id="@android:id/background"
            android:drawable="@layout/seekbar_background" />
    
        <item android:id="@android:id/progress">
            <clip android:drawable="@layout/seekbar_progress" />
        </item>
    </layer-list>
    
    
    
    seekbar_background.xml

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:shape="line">
    
       <stroke android:width="2dp" android:color="#868686"/>
       <corners android:radius="1dp" />
    </shape>
    
    
    
    seekbar_progress.xml

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:shape="line">
    
       <stroke android:width="2dp" android:color="#ffffff"/>
       <corners android:radius="1dp" />
    </shape>
    

    这行得通吗?安卓:thumb=“@layout/seekbar\u thumb”??