我倾向于写了这样的布局与孩子们LinearLayout
作为根元素和权重动态分配屏幕资源。它使布局定义紧凑,不需要定义额外的ID。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView ... />
<ImageView ... />
...
<ImageView ... />
</LinearLayout>
</ScrollView>
<!-- footer here -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
...
</LinearLayout>
</LinearLayout>
使用RelativeLayout
为根元素,与位于“上面”的底端对齐页脚ScrollView
,然而,可能是在性能方面略胜一筹,但我怀疑它就会在一个noticable不同像这样的简单视图层次结构的情况。 RelativeLayout方法确实需要分配一些id(至少对于页脚,我会说)。
非常感谢,这正是我一直在寻找的。 – anonymous123 2012-04-11 13:24:41
另外我想知道,如果我们使用相对布局,那么您的意思是更好的表现。 – anonymous123 2012-04-11 13:25:12
布局权重需要一个小部件来测量两次。特别是当你开始用非零权重嵌套'LinearLayout'时,这是一件坏事,因为测量次数呈指数增长。这正是现今Lint工具在这些情况下向您显示警告的原因。通常(也是在这种情况下),您可以使用“RelativeLayout”实现相同的布局。如果你需要一个例子,我很乐意将它添加到上面的答案中。 – 2012-04-11 19:21:50