【问题标题】:Problems adding a footer with RelativeLayout使用 RelativeLayout 添加页脚时出现问题
【发布时间】:2014-05-09 17:47:56
【问题描述】:

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

 <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 重叠。 我尝试在ScrollView 中使用android:layout_above="@id/layout_footer1",它在图形编辑器中似乎可以工作,但是当我尝试启动应用程序时,由于layout_footer1,它给了我一个未知的资源错误。

【问题讨论】:

    标签: android android-layout footer android-relativelayout


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        您应该将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>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-07-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-07-29
          相关资源
          最近更新 更多