Search code examples
androidandroid-activityandroid-linearlayoutandroid-scrollview

Move android components in a LinearLayout


I have an Activity which has an EditText programmatically added to a LinearLayout inside a ScrollView.

ScrollView <- LinearLayout <- EditText(s)

Is possible to rearrange their position by seting X and Y axis or something as Swing does for Components?

This is my code:

for (Field classField : todoFields) {

    CustomEditText field = new CustomEditText(this);

    field.setName(classField.getName());

    layoutFieldWrapper.addView(field);

}

EDIT:

Can I freely move components around the interface, for instance: Put component next to another by setting the same Y and different X or overlap any of them to other, ecc.. does it's possible?


Solution

  • You can use RelativeLayout. Replace it with your LinearLayout inside your ScrollView. This layout gives you much accessibility. You can move your views in your user interface freely using this type of layout. You will have to play around with some attributes and try like: gravity, layout_centerVertical, padding, layout_margin, layout_width, layout_height, layout_below, layout_toRightOf, and a lot more...

    Reference Link: http://developer.android.com/guide/topics/ui/layout/relative.html