android - 无法将页脚添加到 ScrollView - android

标签 android android-layout layout android-studio android-scrollview

我目前正在开发一个移动应用程序,但在尝试将页脚放在 ScrollView 下时遇到了问题。

这是我的代码:

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



    <RelativeLayout

        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bottomcontent"
        android:orientation="vertical"
        android:background="@drawable/border">
            //the footer is added dynamically
    </RelativeLayout>

<ScrollView
    android:layout_weight="1"
    android:id="@+id/scroller"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/contentcontainer">
        <LinearLayout
            android:id="@+id/scrollcontentcontainer"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            //the content is added dynamically from a layout template
        </LinearLayout>
    </LinearLayout>
</ScrollView>
</RelativeLayout>

scrollview的内容是一组相对布局,里面有一些buttons和textviews。它基于我多次膨胀的布局。

页脚只是一个带有一些按钮的线性布局。

问题是我尝试了我在 Internet 上找到的所有不同解决方案,但没有一个有效。在我的例子中,页脚卡在 ScrollView 的内容下面,而不是 ScrollView 本身下面,所以我必须向下滚动直到内容结束才能到达我的页脚。但是页脚应该保留在屏幕底部......

我也尝试了这些解决方案,但没有任何效果: - http://www.javacodegeeks.com/2013/10/android-fixed-header-and-footer-with-scrollable-content-layout-example.html (当我尝试这个时,我在屏幕顶部有一个页脚,没有别的......) - http://www.byteslounge.com/tutorials/android-fixed-header-and-footer-with-scrollable-content-layout-example 和其他一些(效果不佳!)

我也尝试了所有可能的事情,比如使用重力、重量、fillViewPort、对齐底部……但不可能得到预期的结果。 最小API设置为14,我用的是android studio。

谢谢大家的帮助!

编辑1: 边框可绘制 `在这里输入代码

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:bottom="-2dp"
        android:left="-2dp"
        android:right="-2dp"
        android:top="2dp">
        <shape android:shape="rectangle" >
            <stroke
                android:width="1dp"
                android:color="#000000" />

            <solid android:color="#3b010101" />

            <padding android:left="10dp"
                android:right="10dp"
                android:top="10dp"
                android:bottom="10dp" />
        </shape>
    </item>

</layer-list>

最佳答案

您可以尝试以下操作,我在 RelaveLayout 中添加 ScrollView 时也遇到了麻烦。

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

    <RelativeLayout
        android:id="@+id/bottomcontent"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@drawable/border">
        <!---add something there eg:-->

      <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:text="Test"/>

     </RelativeLayout>


    <ScrollView
        android:id="@+id/scroller"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@id/bottomcontent"
        android:layout_alignParentTop="true">

        <LinearLayout
            android:id="@+id/contentcontainer"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/scrollcontentcontainer"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

enter image description here .

我在 this documentation 中找到了以下内容.这肯定会导致问题

Note: In platform version 17 and lower, RelativeLayout was affected by a measurement bug that could cause child views to be measured with incorrect MeasureSpec values. (See MeasureSpec.makeMeasureSpec for more details.) This was triggered when a RelativeLayout container was placed in a scrolling container, such as a ScrollView or HorizontalScrollView. If a custom view not equipped to properly measure with the MeasureSpec mode UNSPECIFIED was placed in a RelativeLayout, this would silently work anyway as RelativeLayout would pass a very large AT_MOST MeasureSpec instead.

This behavior has been preserved for apps that set android:targetSdkVersion="17" or older in their manifest's uses-sdk tag for compatibility. Apps targeting SDK version 18 or newer will receive the correct behavior

关于android - 无法将页脚添加到 ScrollView - android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32302970/

相关文章:

android - ViewPagerIndicator 的 TitlePageIndicator 阻止 fragment 显示并导致滑动不起作用

android - `remember` 是否仅适用于 `MutableState` 变量?

android - xmpp在android应用程序中发送和接收消息

java - 未在模块中找到 Android Facet

css - 三列可变宽度 CSS 页面布局,右列展开

android-layout - 如何使用整数设置颜色?

android - BottomSheets 的侧滑画廊?

android - 分隔符填充,忽略它

wpf - WPF中TableColumn和GridColumn的Auto和Star的区别

html - Bootstrap 3 - 部分 - 如何居中图像