本文介绍了如何在搜索栏拇指中间增加TextView的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Android的工作的。我想打一个搜索栏。在搜索栏的拇指我想显示进度(可能使用了的TextView 在拇指它一起移动拇指对齐)。

I am working in Android. I want to make a SeekBar. In thumb of SeekBar i want to show progress (probably on a TextView aligned over thumb which moves along with thumb).

这是我的 XML 的的搜索栏的TextView

<SeekBar
    android:id="@+id/ProgressBar01"
    android:layout_width="fill_parent"
    android:paddingLeft="10px"
    android:paddingRight ="10px"
    android:layout_height="70dp"
    android:layout_below="@+id/incentives_textViewBottemLeft"
    android:max="10"
    android:progressDrawable="@drawable/incentive_progress"
    android:secondaryProgress="0"
    android:thumb="@drawable/incentives_progress_pin"
    android:focusable="false" />

<TextView
    android:id="@+id/incentives_textViewAbove_process_pin"
    android:layout_width="fill_parent"
    android:layout_height="20dp"
    android:layout_below="@+id/incentives_textViewBottemLeft"
    android:layout_marginTop="11dp"
    android:text=""
    android:textStyle="bold"
    android:textColor="#FFe4e1"
    android:textSize="15sp" />

和本我的code键使对齐文本

and this my code to make align for text

int xPos = ((mSkbSample.getRight() - mSkbSample.getLeft()) / mSkbSample.getMax()) * mSkbSample.getProgress();
v1.setPadding(xPos+m,0,0,0);
v1.setText(String.valueOf(progress).toCharArray(), 0, String.valueOf(progress).length());  

不过文字显示不进的中心的是经验。请建议我我应该怎么做这个。

But text is not displaying into center of that thumb. Please suggest me what should i do for this.

推荐答案

如果我理解你的问题吧,你要放置拇指内侧文上像这样一个搜索栏:

If I understand your question right, you want to place text inside of the thumb on a seekbar like so:

Android的搜索栏不公开任何公共或受保护的方法,可以让你设置在大拇指的文本。所以你不能实现了Android搜索栏的解决方案不变。

The Android Seekbar doesn't expose any public or protected methods that allows you to set a text in the thumb. So you can't implement a solution with the Android SeekBar as is.

作为一个解决方案,您可以编写自己的CustomSeekBar。

As a solution, you can write your own CustomSeekBar.

Android的<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.3.5_r1/android/widget/SeekBar.java#SeekBar">SeekBar扩展<一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.3.5_r1/android/widget/AbsSeekBar.java#AbsSeekBar">AbsSeekBar.它在AbsSeekBar大拇指的位置设置,像这样:

The Android SeekBar extends AbsSeekBar. It's in AbsSeekBar that the thumb's position is set, like so:

 private void setThumbPos(int w, Drawable thumb, float scale, int gap) {
    int available = w - mPaddingLeft - mPaddingRight;
    int thumbWidth = thumb.getIntrinsicWidth();
    int thumbHeight = thumb.getIntrinsicHeight();
    available -= thumbWidth;

    // The extra space for the thumb to move on the track
    available += mThumbOffset * 2;

    //Determine horizontal position
    int thumbPos = (int) (scale * available);

    //Determine vertical position
    int topBound, bottomBound;
    if (gap == Integer.MIN_VALUE) {
        Rect oldBounds = thumb.getBounds();
        topBound = oldBounds.top;
        bottomBound = oldBounds.bottom;
    } else {
        topBound = gap;
        bottomBound = gap + thumbHeight;
    }

    //Set the thumbs position
    thumb.setBounds(thumbPos, topBound, thumbPos + thumbWidth, bottomBound);
}

和在AbsSeekBar的OnDraw()方法,拇指得出:

and in AbsSeekBar's onDraw() method, the thumb is drawn:

mThumb.draw(canvas);

要实现自己的搜索栏,首先创建一个扩展AbsSeekBar一个CustomSeekBar类。然后覆盖在你的CustomSeekBar类AbsSeekBar的setThumPos()方法,并在其中设置自己的自定义滑块的位置。

To implement your own SeekBar, you first create a CustomSeekBar class that extends AbsSeekBar. You then override AbsSeekBar's setThumPos() method in your CustomSeekBar class, and there set the position of your own custom thumb.

您定制的拇指是一个View或ViewGroup中,例如:的LinearLayout,与背景绘制和一个TextView的进度百分比文本。

Your custom thumb would be a View or ViewGroup,e.g. LinearLayout, with a background drawable and a TextView for the percentage progress text.

您然后必须决定如何编写进度百分比,以自定义的拇指。你可以写在一个新的writeTextOnThumb方法(在大拇指上的百分比进度文本)被称为内setThumbPos(),或者你可以将其暴露在你CustomSeekBar的API的公共方法。

You then have to decide how to write the percentage progress to the custom thumb. You could write the percentage progress text on the thumb in a new writeTextOnThumb method() called inside setThumbPos(), or you could expose it as a public method in your CustomSeekBar's API.

这篇关于如何在搜索栏拇指中间增加TextView的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 02:02