填写拇指右侧的进度

时间:2016-07-27 16:01:33

标签: android android-seekbar

我希望能够将该区域填充到右侧而不会影响拇指左侧的填充

enter image description here

我的进度XML

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <size android:height="90dp"/>
                <stroke android:width="2dp" android:color="#00ef3c"/>
                <solid android:color="#00ffffff" />
            </shape>
        </clip>
    </item>
    <item android:id="@+id/background">
        <clip>
            <shape>
                <size android:height="90dp"/>
                <solid android:color="#bd767676" />
            </shape>
        </clip>
    </item>
</layer-list>

自定义搜索栏样式

<style name="SeekbarCustom">
    <item name="android:indeterminate">false</item>
    <item name="android:progressDrawable">@drawable/video_seek_bar_progress</item>
    <item name="android:thumb">@drawable/video_seek_bar_thumb</item>
    <item name="android:thumbOffset">8px</item>
    <item name="android:focusable">true</item>
</style>

1 个答案:

答案 0 :(得分:0)

所以我终于解决了它。不知道这是否是最好的解决方案。但它会做到

我所做的是让SecondaryProgress属性行为具有填充物。然后我将其重力设定为从右侧开始。然后我就创建了一个监听器来改变它的进度。

听众

binding.fragmentPostVideoSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
  @Override
  public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
    int progress = seekBar.getProgress();
    seekBar.setSecondaryProgress(100 - progress);
  }
});

XML drawable

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <size android:height="90dp"/>
                <stroke
                  android:width="2dp"
                  android:color="#00ef3c"/>
                <solid android:color="#00ffffff"/>
            </shape>
        </clip>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip android:gravity="right">
            <shape>
                <size android:height="90dp"/>
                <solid android:color="#b7797979"/>
            </shape>
        </clip>
    </item>
</layer-list>