【问题标题】:Remove thumb text from rangeseekbar从 rangeeekbar 中删除拇指文本
【发布时间】:2016-03-28 08:01:06
【问题描述】:

我有一个范围搜索栏,如下图所示

我使用以下代码进行范围搜索栏集成:

https://github.com/yahoo/android-range-seek-bar

我的问题是我想在滚动时删除搜索栏 2751064 的值,并删除 Min 和 Max 标签,这样可以吗?您的所有建议都很有价值。

【问题讨论】:

  • IntelliJ Amiya:我在哪里找到 layout.addView(rangeSeekBar);?

标签: android android-seekbar seekbar-thumb


【解决方案1】:

使用编译:

'org.florescu.android.rangeseekbar:rangeseekbar-library:0.3.0'

并添加您的布局:

<org.florescu.android.rangeseekbar.RangeSeekBar xmlns:app="http://schemas.android.com/apk/res-auto" app:showLabels="false" app:valuesAboveThumbs="false" />

【讨论】:

    【解决方案2】:
    【解决方案3】:

    所有这些文本都是在RangeSeekbaronDraw() 方法中绘制的。您应该查看onDraw() 中的代码,找到以下行:

    canvas.drawText()
    

    然后删除或修改它。

    【讨论】:

      【解决方案4】:

      试试这个

      把它放在你的 Gradle 中:

      compile 'org.florescu.android.rangeseekbar:rangeseekbar-library:0.3.0'
      

      这在你的 Xml 文件中

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:tools="http://schemas.android.com/tools"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:paddingLeft="@dimen/activity_horizontal_margin"
       android:paddingRight="@dimen/activity_horizontal_margin"
       android:paddingTop="@dimen/activity_vertical_margin"
       android:paddingBottom="@dimen/activity_vertical_margin"
       tools:context=".MainActivity">
      
      <LinearLayout
          android:id="@+id/seekbar_placeholder"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"/>
      </RelativeLayout>
      

      并在您的活动中添加此代码:

       RangeSeekBar<Integer> rangeSeekBar = new RangeSeekBar<Integer>(this);
       // Set the range
       rangeSeekBar.setRangeValues(15, 90);
       rangeSeekBar.setSelectedMinValue(20);
       rangeSeekBar.setSelectedMaxValue(88);
      
       // Add to layout
       LinearLayout layout = (LinearLayout) findViewById(R.id.seekbar_placeholder);
       layout.addView(rangeSeekBar);
      

      【讨论】:

        【解决方案5】:

        在 RangeSeekBar java 文件上,删除:

        canvas.drawText(minLabel, 0, minMaxHeight, paint);
        canvas.drawText(maxLabel, getWidth() - minMaxLabelSize, minMaxHeight, paint);
        

        用于最小和最大标签

        并删除

        if (!selectedValuesAreDefault) {
                paint.setTextSize(mTextSize);
                paint.setColor(Color.WHITE);
                // give text a bit more space here so it doesn't get cut off
                int offset = PixelUtil.dpToPx(getContext(), TEXT_LATERAL_PADDING_IN_DP);
        
                String minText = String.valueOf(getSelectedMinValue());
                String maxText = String.valueOf(getSelectedMaxValue());
                float minTextWidth = paint.measureText(minText) + offset;
                float maxTextWidth = paint.measureText(maxText) + offset;
        
                if (!mSingleThumb) {
                    canvas.drawText(minText,
                            normalizedToScreen(normalizedMinValue) - minTextWidth * 0.5f,
                            mDistanceToTop + mTextSize,
                            paint);
        
                canvas.drawText(maxText,
                        normalizedToScreen(normalizedMaxValue) - maxTextWidth * 0.5f,
                        mDistanceToTop + mTextSize,
                        paint);
        

        拇指文字

        另外,因为你把它缩短了,你会想要设置

        public static final int HEIGHT_IN_DP = 18;
        

        【讨论】: