I have an Activity with a ScrollView and I want to have a footer below it. I tried this:

 <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>

The problem is, that the footer overlaps the ScrollView. I tried to use android:layout_above="@id/layout_footer1" in the ScrollView and it SEEMS TO WORK in the graphical editor, but when I try to start the app, it gives me an unknown recource error because of layout_footer1.

有帮助吗?

解决方案 2

You should put the ScrollView tag below the footer and use android:layout_above="@id/layout_footer1" for it like this:

<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>

其他提示

You have to put the xml tag of the footer above the ScrollView. And then you should add android:layout_above="R.id.layout_footer1" into you ScrollView.

You can add android:layout_below="@+id/scrollView1" in the RelativeLayout of the footer. It will do the same job

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top