开发者

How to write a TextView in a determined coordinates of the screen? (frame layout)

开发者 https://www.devze.com 2023-04-09 21:43 出处:网络
I have a app that shows the camera view on the screen on a FrameLayout. The screen is in fixed LandSape mode.

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


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号