Android TextView宽度单位?

时间:2017-06-19 12:30:37

标签: android textview

我正在尝试检索加载了文本的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中获取文本视图的宽度。

感谢。

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:-1)

txt_MyText.getWidth() // this will get you the view's width
txt_MyText.getHeight() // this will get you the view's height

返回的值将以像素为单位