获取当前搜索栏进度/次级进度在屏幕上的位置? [英] Get onscreen position of current seekbar progress/secondary progress?

查看:58
本文介绍了获取当前搜索栏进度/次级进度在屏幕上的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to customize the look of a seekbar by overriding the onDraw() method - I need to find the current progress/secondary progress position on screen.

我知道如何使用 getProgress() getSecondaryProgress()获得当前进度/第二进度,但这不能反映屏幕上的位置.我以为我可以获取进度可绘制对象,并获取可绘制对象的边界,或者获取用于进度的clipDrawable的级别,如下所示:

I know how to get the current progress/secondary progress with getProgress() and getSecondaryProgress() but this does not reflect the position onscreen. I thought I could get the progress drawable and get the bounds of the drawable, or the level of the clipDrawable used for the progress like so:

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
        }

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

but the values I get do no reflect the onscreen position either! Does anyone know how I can get these values?

推荐答案

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

I got around this by setting the max progress to the width of the screen:

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

这篇关于获取当前搜索栏进度/次级进度在屏幕上的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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