添加动态文本在Android的搜索栏拇指 [英] Add dynamic text over Android SeekBar thumb

查看:122
本文介绍了添加动态文本在Android的搜索栏拇指的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我这个!

我想,并试图让这个自定义搜索栏在Android 2.2及我所做的一切接缝是错误的!没有任何人有这个一些经验。我想要做的事情,是要显示搜索栏在搜索栏​​的拇指图片...

I'm trying and trying to make this custom SeekBar in Android 2.2 and everything I do seams to be wrong! Does anybody have some experiences with this. The thing I'm trying to do, is to display the value of the seekbar over the thumb image of the SeekBar...

推荐答案

我假设你已经扩展基类,所以你有这样的:

I assume you've already extended the base class, so you have something like:

public class SeekBarHint extends SeekBar {
  public SeekBarHint (Context context) {
      super(context);
  }

  public SeekBarHint (Context context, AttributeSet attrs, int defStyle) {
      super(context, attrs, defStyle);
  }

  public SeekBarHint (Context context, AttributeSet attrs) {
      super(context, attrs);
  }
}

现在你重写的OnDraw 法的一些自己的code。插入以下内容:

Now you override the onDraw method with some of your own code. Insert the following:

@Override
protected void onDraw(Canvas c) {
    super.onDraw(c);
}

现在,你想画拇指附近的一些文字,但没有一个方便的方式来获得拇指的x坐标。我们只需要一点点数学。

Now, you want to draw some text near the thumb, but there isn't a convenient way to get the thumb's x-position. We just need a little math.

@Override
protected void onDraw(Canvas c) {
    super.onDraw(c);
    int thumb_x = ( (double)this.getProgress()/this.getMax() ) * (double)this.getWidth();
    int middle = this.getHeight()/2;
    // your drawing code here, ie Canvas.drawText();
}

这篇关于添加动态文本在Android的搜索栏拇指的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆