【问题标题】:Android TextView Width units? [duplicate]Android TextView 宽度单位? [复制]
【发布时间】:2017-11-21 16:10:36
【问题描述】:

我正在尝试检索加载文本的 TextView 的宽度。这是我使用的代码,

txt_MyText.measure(0, 0);
float textViewWidth = txt_MyText.getMeasuredWidth();

现在这段代码返回值为 25882.0

我正在三星 Galaxy S6 Edge 上进行测试,它有一个屏幕 三星 Galaxy S6、S6 Edge 5.1″ 1440×2560 尺寸

我不确定这个值是以什么单位返回的。在我的 XML 中,我将 TextView 宽度设置为 WRAP_CONTENT。

如何在 PIXELS 中获取文本视图的宽度。

谢谢。

【问题讨论】:

  • 框架提供的所有值都以像素为单位。

标签: android textview


【解决方案1】:
【解决方案2】:
txt_MyText.getWidth() // this will get you the view's width
txt_MyText.getHeight() // this will get you the view's height

返回值将以像素为单位

【讨论】:

    猜你喜欢
    • 2015-04-14
    • 1970-01-01
    • 2012-07-14
    • 1970-01-01
    • 2017-02-03
    • 1970-01-01
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多