【问题标题】:Get onscreen position of current seekbar progress/secondary progress?获取当前搜索栏进度/辅助进度的屏幕位置?
【发布时间】:2012-05-04 15:31:13
【问题描述】:

我正在尝试通过覆盖 onDraw() 方法来自定义搜索栏的外观 - 我需要在屏幕上找到当前进度/次要进度位置。

我知道如何使用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
        }

但我得到的值也不反映屏幕上的位置!有谁知道我如何获得这些值?

【问题讨论】:

    标签: android customization seekbar


    【解决方案1】:

    我通过将最大进度设置为屏幕宽度来解决这个问题:

        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);
    

    【讨论】:

      猜你喜欢
      • 2017-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-18
      相关资源
      最近更新 更多