Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.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
如何在android布局中创建固定页脚?_Android_Layout - Fatal编程技术网

如何在android布局中创建固定页脚?

如何在android布局中创建固定页脚?,android,layout,Android,Layout,我使用下面的代码显示活动底部的按钮 <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" > <Bu

我使用下面的代码显示活动底部的按钮

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

         android:text="Get more"
       />
       </RelativeLayout> 

和上面的列表视图。当我在listview中显示更多数据时,此按钮窗格会向下移动。有人能指导我如何将其固定在“活动”的底部吗


任何帮助都将不胜感激

android:layout\u alignParentBottom属性必须在
RelativeLayout
的元素中声明,而不是在
RelativeLayout
本身中声明(除非有另一个
RelativeLayout
作为父项)

您应该这样做,在
RelativeLayout
中使用
ListView
,同时:

<RelativeLayout 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content"         
 android:layout_centerHorizontal="true">
  <ListView ...>
  <Button android:id="@+id/btnGetMoreResults"
   android:layout_height="wrap_content" 
   android:layout_width="wrap_content"     
   android:text="Get more"
   android:layout_alignParentBottom="true" />
</RelativeLayout> 

选择为正确的答案有错误,按钮将隐藏列表视图的下部。正确的方法是先声明按钮,然后将列表放在按钮上方

<Button android:id="@+id/btnGetMoreResults"
   android:layout_height="wrap_content" 
   android:layout_width="wrap_content"     
   android:text="Get more"
   android:layout_alignParentBottom="true"/>

<ListView 
   ...
   android:layout_above="@id/btnGetMoreResults"/>

例如,如果在滚动视图中有所有可滚动元素,则应执行以下操作:

<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
    android:layout_height="match_parent"
        style="@style/rootElement"
    >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

            <!-- texts, buttons, images and anything that you want to scroll -->

        </ScrollView>

    <LinearLayout 
        android:orientation="vertical" 
        style="@style/footer"
        android:id="@+id/footer"            
            android:layout_alignParentBottom="true"
        >

    </LinearLayout>

</RelativeLayout>

请注意,如果希望固定页脚,则不应将其放在可滚动内容所在的ScrollView中。将其设为RelativeLayout的子级,并将
layout\u alignParentBottom
设置为true。在这种情况下,可能需要在ScrollView的底部添加一个填充(以便最后一个元素不会被页脚隐藏)


除了
ScrollView

之外,其他元素的想法也很类似,我一天试了几个小时,但这很快就奏效了:)