使用RelativeLayout添加页脚时出现问题

问题描述 投票:1回答:3

我有一个ActivityScrollView,我想在它下面有一个页脚。我试过这个:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

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

      .......

    </ScrollView>

    <RelativeLayout
        android:id="@+id/layout_footer1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <View
            android:id="@+id/footer_topline"
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="#0075b5" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="84dp"
            android:layout_height="42dp"
            android:layout_marginBottom="15dp"
            android:layout_marginLeft="10dp"
            android:maxHeight="30dp"
            android:maxWidth="30dp"
            android:src="@drawable/logo" />
    </RelativeLayout>

</RelativeLayout>

问题是,页脚与ScrollView重叠。我试图在android:layout_above="@id/layout_footer1"中使用ScrollView并且它在图形编辑器中看起来工作,但是当我尝试启动应用程序时,由于layout_footer1,它给了我一个未知的资源错误。

android android-layout footer android-relativelayout
3个回答
1
投票

您应该将ScrollView标记放在页脚下方并使用android:layout_above="@id/layout_footer1",如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<!-- Footer -->
<RelativeLayout
    android:id="@+id/layout_footer1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" >

    <View
        android:id="@+id/footer_topline"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#0075b5" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="84dp"
        android:layout_height="42dp"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="10dp"
        android:maxHeight="30dp"
        android:maxWidth="30dp"
        android:src="@drawable/logo" />
</RelativeLayout>

<!-- Scroll view -->
<ScrollView
    android:id="@+id/scrollView1"
    android:layout_above="@id/layout_footer1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
</ScrollView>

</RelativeLayout>

3
投票

你必须将页脚的xml标记放在ScrollView上方。然后你应该将android:layout_above="R.id.layout_footer1"添加到你的ScrollView


1
投票

你可以在页脚的android:layout_below="@+id/scrollView1"中添加RelativeLayout。它会做同样的工作

© www.soinside.com 2019 - 2024. All rights reserved.