如何摆脱相对布局或使用免费布局。 (机器人)

时间:2014-09-20 06:14:36

标签: android android-layout layout

相对布局对我来说一直很痛苦,每当我移动一件事时,至少会有其他几件事跟随。我正在寻找一种方法来禁用相对布局或使用允许我移动任何我想要的任何地方的布局。从我看到的网格布局,线性布局和框架布局不允许这样做。任何人都可以给我一些建议,或者可能我可能不知道如何使用这些布局大声笑。

2 个答案:

答案 0 :(得分:3)

您应该始终知道何时使用哪种布局?


您的选择取决于您的要求

Have a look at this answer i posted on a similar question

说明:

enter image description here


更多信息:

<强> FrameLayout :: enter image description here RelativeLayout :: enter image description here TableLayout :: enter image description here


注意: - 绝对布局已被删除

来源 Android Developers


Note that Relative Layout reduces your view hierarchy to maximum extent

优化 :: 查看Optimizing Layout Hierarchies

视野越少,越好 ::

  1. The number one goal for your layouts should be using the fewest number of Views possible. The fewer Views you have to work with, the faster your application will run. Excessive nesting of Views further slows down your application.

  2. A RelativeLayout hierarchy will typically use fewer Views and have a flatter tree than a LinearLayout hierarchy. With LinearLayout, you must create a new LinearLayout every time you want to change the orientation of your views – creating additional Views and a more nested hierarchy. As a result, it is recommended that you first use RelativeLayout for any layout that has any complexity. There is a high probability you will reduce the number of Views – and the depth of your View tree – by doing so.


答案 1 :(得分:0)

ViewGroup文档将帮助您直接为初学者设置一些定义。

你不能完全摆脱RelativeLayout本身,你总是需要将你的视图组织成一些ViewGroup / Layout(这两个词是可以互换的)。我发现基本的东西你几乎总能得到RelativeView,LinearView(或者最重要的是两者的组合)来提供你需要的行为。

RelativeLayout ,必须指定彼此相关的内容,

LinearLayout orientation:vertical 当你需要在彼此顶部显示的东西时,

LinearLayout oreintation:horzontal 当你需要并排展示的东西时。

将这三种类型的组嵌套在一起需要一段时间才能掌握,但是非常强大。

link总是对我有帮助......希望这有帮助