【问题标题】:How to get the middle position of a button where it ends?如何获得按钮结束的中间位置?
【发布时间】:2015-04-14 08:30:04
【问题描述】:

我有一个椭圆形的按钮。我想知道按钮的中间位置,但在最后一个坐标中,按钮结束的位置。

我尝试了以下代码的帮助,但是它不起作用。

View v;
int pos= v.getX()+ v.getWidth();

但是它返回的位置超出了视野范围。我也尝试过使用下面的代码来做到这一点。

Rect rectf = new Rect();
v.getLocalVisibleRect(rectf);
int pos = v.getX() + rectf.width

【问题讨论】:

  • 你要的是中心坐标还是终点坐标?
  • 结束坐标对我有用,但我的按钮是椭圆形的!!

标签: android android-layout android-view android-button


【解决方案1】:
int location[] = new int[2];
v.getLocationOnScreen(location);
int pos = location[0] + v.getMesuredWidth();

【讨论】:

  • 这就是问题所在......我也这样做了,但它跨越了观点
  • 我的确切要求是我想从一个按钮末端画一条线到另一个按钮 x 位置,以便它们看起来连接。
猜你喜欢
  • 1970-01-01
  • 2014-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-23
  • 2016-08-01
  • 2017-04-17
  • 2016-02-15
相关资源
最近更新 更多