2

我已经实现了一个简单的 SeekBar,当用户触摸它时,它的拇指会变大。虽然这在 Marshmallow 设备上运行良好,但在 Lollipop 上却不行。

在棉花糖中——(应该是这样的) 接触——
默认拇指 - 正确显示

大拇指 - 显示正确

在棒棒糖中-(这是错误的)
在此处输入图像描述

两个问题是——

  1. 拇指不再垂直居中。
  2. 当用户触摸拇指时,进度没有明显变化。

这是我的活动布局-

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipChildren="false">

        <SeekBar
            android:id="@+id/seekBar_main_green"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_marginTop="20dp"
            android:max="255"
            android:thumb="@drawable/custom_thumb_green" />

    </RelativeLayout>
</ScrollView>

这是我的课-

sbGreen.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // Changing background color of some other view
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            sbGreen.setThumb(ContextCompat.getDrawable(MainActivity.this, R.drawable.custom_thumb_green_large));
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            sbGreen.setThumb(ContextCompat.getDrawable(MainActivity.this, R.drawable.custom_thumb_green));
        }
    });

这是我的drawables
-custom_thumb-

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:bottom="10dp"
        android:left="10dp"
        android:right="10dp"
        android:top="10dp" >

        <shape android:shape="oval">
            <size
                android:width="10dp"
                android:height="10dp" />
            <solid android:color="#00af00" />
        </shape>
    </item>

    <item>
        <shape android:shape="oval">
            <solid android:color="#50008000"/>
            <size android:height="20dp" android:width="20dp"/>
        </shape>
    </item>
</layer-list>

custom_thumb_large-

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:bottom="30dp"
        android:left="30dp"
        android:right="30dp"
        android:top="30dp" >

        <shape android:shape="oval">
            <size
                android:width="10dp"
                android:height="10dp" />
            <solid android:color="#00af00" />
        </shape>
    </item>

    <item>
        <shape android:shape="oval">
            <solid android:color="#50008000"/>
            <size android:height="40dp" android:width="40dp"/>
        </shape>
    </item>
</layer-list>

我尝试过的事情-

非常欢迎任何帮助或建议。

4

0 回答 0