0

我有一个应用程序,它在FrameLayout的屏幕上显示相机视图。屏幕处于固定 LandSape 模式。

我需要用动态确定的屏幕坐标编写一个 textView。坐标以百分比确定,例如:

将文本视图写在 x=80% 的屏幕和 y=20% 的屏幕上。将 textview 写在 x=35% 的屏幕和 y=55% 的屏幕上。

怎么做?我已经有了百分比,我只需要知道如何使用它们将 textview 写入 frameLayout 的所需位置

欢迎代码示例

谢谢

4

1 回答 1

1

您可能想要添加一个AbsoluteLayout覆盖,使用屏幕尺寸计算屏幕上的绝对位置并相应地设置视图的位置。

编辑

由于 AbsoluteLayout 已被弃用,您可以使用以下技术将文本定位在RelativeLayout中:

text = (TextView) findViewById(R.id.text);

RelativeLayout.LayoutParams position = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

position.leftMargin = 20;
position.topMargin  = 40;

text.setLayoutParams(position);
于 2011-09-29T07:27:59.913 回答