如何在屏幕上动态移动一个TextView? (的FrameLayout) [英] How to move a Textview dynamically on the screen? (framelayout)

查看:157
本文介绍了如何在屏幕上动态移动一个TextView? (的FrameLayout)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,显示了一个的FrameLayout屏幕上的摄像机视图。屏幕是固定横向模式。

我需要编写与屏幕的动态确定坐标,一个TextView。坐标中的百分比测定,例如

写的TextView上coorinates屏幕和放大器的X = 80%; Y =屏幕的20%。写的TextView上coorinates屏幕和放大器的X = 35%; Y =屏幕的55%。

该怎么办呢?我已经有了百分比,我只需要知道如何使用它们来写的TextView上的FrameLayout

的所需位置

code事例令人鼓舞

我试着用这个,但没有作品,TextView的不动:

  TextView的POI .....等等等等
poi.setLayoutParams(新的LayoutParams((int)的(W *(xCoordPercent / 100))中,h / 2));

感谢


解决方案

  MarginLayoutParams PARAMS =(MarginLayoutParams)poi.getLayoutParams();
params.leftMargin = 80;
//此处100表示​​100像素,而不是80%的父视图的宽度
//你可能需要计算的百分比转换为像素。
params.topMargin = 50;
poi.setLayoutParams(PARAMS);

这可能会有帮助。

I have a app that shows the camera view on the screen on a FrameLayout. The screen is in fixed LandScape mode.

I need to write a textView with dynamically determined coordinates of the screen. The coordinates are determined in percentages, for example :

write the textview on the coorinates x=80% of the screen & y=20% of the screen. write the textview on the coorinates x=35% of the screen & y=55% of the screen.

how to do it? i already have the percentages, i only need to know how to use them to write the textview on the desired position of the frameLayout

code examples are welcome

i tried with this but doesn't works, the textview isn't moved:

TextView poi..... etc etc
poi.setLayoutParams(new LayoutParams((int)(w*(xCoordPercent/100)), h/2));

thanks

解决方案

MarginLayoutParams params=(MarginLayoutParams )poi.getLayoutParams();
params.leftMargin=80;
//here 100 means 100px,not 80% of the width of the parent view
//you may need a calculation to convert the percentage to pixels. 
params.topMargin=50;
poi.setLayoutParams(params);

This may help.

这篇关于如何在屏幕上动态移动一个TextView? (的FrameLayout)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆