Question

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

I need to write a textView with dinamically 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 allready 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

thanks

Was it helpful?

Solution

You might want to add an AbsoluteLayout overlay, calculate the absolute position on the screen using screen dimensions and set the position of the view accordingly.

Edit

Since the AbsoluteLayout is deprecated, you can use the following technique to position the text in a 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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top