美文网首页
Android日常--自定义View

Android日常--自定义View

作者: 拉弓的松鼠在旋转 | 来源:发表于2017-03-25 12:52 被阅读0次

    获取字体的长度

    Rect rect = new Rect();

    paint.getTextBounds(getLabel(), 0, getLabel().length(), rect);

    int strwid = rect.width()/2;

    int strhei = rect.height()/2;

    canvas.drawText(getLabel(), cx-strwid, cy+strhei, paint);

    获取屏幕size

    @SuppressLint("NewApi")

    public static Point getDisplaySize(Activity act) {

    WindowManager m = act.getWindowManager();

    Display d = m.getDefaultDisplay(); // 为获取屏幕宽、高

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {

    Point outSize = new Point();

    d.getSize(outSize);

    return outSize;

    } else {

    Point p = new Point(d.getWidth(), d.getHeight());

    return p;

    }

    }

    }

    相关文章

      网友评论

          本文标题:Android日常--自定义View

          本文链接:https://www.haomeiwen.com/subject/pnhcottx.html