需要Android固定页脚的帮助才能进行线性布局

ano*_*123 2 java android android-linearlayout

我的enter code hereandroid布局xml文件中有<.ImageView> s(图标),包含在a <ScrollView>.

例如.

<.ScrollView><br>
<.LinearLayout><br>
<.ImageView> ...<./ImageView><br>
<./LinearLayout><br>
<./ScrollView>
Run Code Online (Sandbox Code Playgroud)

对于这种布局,我想附加一个固定的页脚.基本上屏幕底部有一个小标签,即使我一直向下滚动或一直向上滚动,它仍会停留.

MH.*_*MH. 5

我倾向于使用LinearLayoutas root元素编写这样的布局,并在子节点上加权以动态分配屏幕区域.它使布局定义紧凑,不需要定义额外的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>
Run Code Online (Sandbox Code Playgroud)

使用RelativeLayout的根元素,与ScrollView定位"上面"的底端对齐躯,然而,可能是在性能方面略胜一筹,但我怀疑这会成为一个noticable不同在这样一个简单的视图层次的情况.RelativeLayout方法确实需要分配一些ID(至少是页脚,我会说).