Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I dynamically set the position of view in Android?

How can I change the position of view through code? Like changing its X, Y position. Is it possible?

like image 840
Arun Badole Avatar asked Jun 30 '11 13:06

Arun Badole


People also ask

Is this possible to add views in a layout dynamically in Android?

This example demonstrates How to Dynamically Add Views into View. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.

How do I change the position of text in Android Studio?

Use RelativeLayout instead of LinearLayout . There are also many other layouts you can try. Check here for the other type of available layouts. RelativeLayout lets child views specify their position relative to the parent view or to each other (specified by ID).


1 Answers

For anything below Honeycomb (API Level 11) you'll have to use setLayoutParams(...).

If you can limit your support to Honeycomb and up you can use the setX(...), setY(...), setLeft(...), setTop(...), etc.

like image 87
Perishable Dave Avatar answered Sep 20 '22 13:09

Perishable Dave