5

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

Sephy
  • 50,022
  • 30
  • 123
  • 131
NullPointerException
  • 36,107
  • 79
  • 222
  • 382
  • 1
    I think what you are trying to do is animating a TextView. If it is the case, you should have a look at tutorials about it, it's fairly straightforward for basic movements like that and it could give you ideas while you await for more answers here. – Sephy Sep 29 '11 at 07:59
  • no no, i dont want to animate it, i only want to move the textivew on the screen, from left to right, from up to down, dependent of dinamically generated coordinates. Later i will use a image, but now i need to mote a textview – NullPointerException Sep 29 '11 at 08:02

1 Answers1

3
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.

Huang
  • 4,812
  • 3
  • 21
  • 20
  • it doesn't works. POI is still painted in the top left corner of the screen. I have to repaint the window or something? the FrameLayout haves a cameraview on it also. What is wrong? im stuck – NullPointerException Sep 29 '11 at 08:45