简体   繁体   English

在LinearLayout中移动android组件

[英]Move android components in a LinearLayout

I have an Activity which has an EditText programmatically added to a LinearLayout inside a ScrollView . 我有一个Activity ,它以编程方式将EditText添加到ScrollView内的LinearLayout

ScrollView <- LinearLayout <- EditText(s)

Is possible to rearrange their position by seting X and Y axis or something as Swing does for Components? 可以通过设置X轴和Y轴或其他东西来重新排列它们的位置,就像Swing对组件一样吗?

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? 我可以在界面周围自由移动组件,例如:通过设置相同的Y和不同的X将组件放在另一个旁边,或者将它们中的任何一个重叠到另一个,ecc ..这可能吗?

If I get you right then you can call the method with index parameter like this: 如果我说得对,那么你可以使用index参数调用方法,如下所示:

layoutFieldWrapper.addView(field, index);

Hope this is the right suggestion or hint. 希望这是正确的建议或提示。

You can use RelativeLayout . 您可以使用RelativeLayout Replace it with your LinearLayout inside your ScrollView . 将其替换为ScrollViewLinearLayout 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... 您将不得不玩一些属性并尝试:gravity,layout_centerVertical,padding,layout_margin,layout_width,layout_height,layout_below,layout_toRightOf等等......

Reference Link: http://developer.android.com/guide/topics/ui/layout/relative.html 参考链接: http//developer.android.com/guide/topics/ui/layout/relative.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM