2012-05-04 41 views
0

我试图通过覆盖onDraw()方法来自定义seekbar的外观 - 我需要在屏幕上找到当前的进度/二级进度位置。获取当前seekbar进度/二级进度的屏幕位置?

我知道如何通过getProgress()getSecondaryProgress()获得当前进度/二级进度,但这并不反映屏幕上的位置。我想我能得到进步绘制并获得可绘制的边界,或使用clipDrawable的水平进步,像这样:

Drawable progress = getProgressDrawable(); 
     if (progress instanceof LayerDrawable) 
     { 
      Drawable primaryProgress = ((LayerDrawable)progress).findDrawableByLayerId(android.R.id.progress); 
      Rect bounds= primaryProgress.copyBounds();//bounds.left is 0, bounds.right is the screen width 
      ((ClipDrawable)primaryProgress).getLevel();//just gives a value between 0 and 10,000 
     } 

,但我得到的数值做没有任何反映屏幕上的位置!有谁知道我如何获得这些价值?

回答

0

我解决这个必须到最大进步设置为屏幕的宽度:

WindowManager wm = (WindowManager) myAppContext.getSystemService(Context.WINDOW_SERVICE); 
    Display display = wm.getDefaultDisplay(); 
    Point size = new Point(); 
    try{ 
     display.getSize(size);//only works on later versions of android 
    } 
    catch (Exception e) { 

     int width = display.getWidth(); // deprecated 
     int height = display.getHeight(); // deprecated 
     size = new Point(width, height); 
    } 
myProgressBar.setMax(size.x); 
相关问题