Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 需要Android fixed footer帮助进行线性布局吗_Java_Android_Android Linearlayout - Fatal编程技术网

Java 需要Android fixed footer帮助进行线性布局吗

Java 需要Android fixed footer帮助进行线性布局吗,java,android,android-linearlayout,Java,Android,Android Linearlayout,我的android布局xml文件中有在这里输入代码s(图标),这些图标由组成 例如 … 对于此布局,我想附加一个固定的页脚。基本上,屏幕底部有一个小标签,即使我一直向下或一直向上滚动,它也会保持不变。类似这样的东西 <.ScrollView> <.LinearLayout> <.ImageView> ...<./ImageView> <./LinearLayout> <./ScrollView> <Linear

我的android布局xml文件中有
在这里输入代码
s(图标),这些图标由
组成

例如





对于此布局,我想附加一个固定的页脚。基本上,屏幕底部有一个小标签,即使我一直向下或一直向上滚动,它也会保持不变。

类似这样的东西

<.ScrollView>
<.LinearLayout>
<.ImageView> ...<./ImageView>
<./LinearLayout>
<./ScrollView>
<LinearLayout>
<-- your footer here -->
</LinearLayout>

...

你也可以这样尝试

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/imageView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/imageView5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/imageView6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/imageView7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/imageView14"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />
            <ImageView
                android:id="@+id/imageView11"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/imageView8"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />
            <ImageView
                android:id="@+id/imageView12"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/imageView9"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

        </LinearLayout>
    </ScrollView>

    <RelativeLayout
        android:id="@+id/relativeLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/blackbg"
        android:layout_alignParentBottom="true" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="Button" />

    </RelativeLayout>

</RelativeLayout>

我倾向于这样写布局,使用
线性布局作为根元素和子元素的权重来动态分配屏幕属性。它使布局定义紧凑,不需要定义额外的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
定位在底部对齐的页脚上方,可能在性能方面稍好一些,尽管我怀疑在这样一个简单的视图层次结构的情况下,它会有明显的不同。RelativeLayout方法确实需要分配一些ID(至少是页脚)。

非常感谢,这正是我所寻找的。另外,我想知道,如果我们使用相对布局,您所说的更好的性能到底意味着什么。布局权重要求一个小部件测量两次。特别是当您开始使用非零权重嵌套
LinearLayout
s时,这是一件坏事,因为测量的数量呈指数增长。这就是为什么现在的Lint工具会在这些情况下向您显示警告。通常(在本例中也是如此)您可以使用
RelativeLayout
实现相同的布局。如果你需要一个例子,我很乐意把它添加到我上面的答案中。
<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>