java - 将底部的线性布局固定为 android 中的页脚

标签 java android android-linearlayout android-scrollview

我做了一个简单的布局xml文件。我一直在逐步解决我的问题。我正在使用 scrolview、linearlayout 和 tableview。我有一个顶部栏,它被锁定在顶部。它永远不会移动。在中间,我有一个 ScrollView ,我需要将最后一个线性布局放在底部作为页脚,我不希望它在用户向下滚动时消失。我想把它锁在那里。

这是我的代码

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

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

         <TableRow
        android:background="@drawable/gradient"
        android:gravity="center">

            .......

         </TableRow>

   </TableLayout>

    <ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/sw_layout"
android:orientation="vertical">

      <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical" >

    <TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="#EEEEEE" >

        <TableRow
        android:id="@+id/tableRowDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

            ..........

            </TableRow>

        </TableLayout>

        /*****************************************/
        /* I want this to be footer at the bottom*/
        /*****************************************/
        <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <Button
            android:id="@+id/btn_date"
            android:layout_height="35dp"
            android:padding="5dp"
            android:drawableLeft="@drawable/calendar"
            android:text="Tarih" />

            <Button
            android:id="@+id/btn_converter"
            android:layout_height="35dp"
            android:padding="5dp"
            android:drawableLeft="@drawable/calendar"
            android:text="Hesap" />
          </LinearLayout>
        /*****************************************/
        /* I want this to be footer at the bottom*/
        /*****************************************/

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

如何将页脚锁定在底部?

最佳答案

您应该使用 RelativeLayout 并在页脚布局中添加标签:android:layout_alignParentBottom="true" ;对于你的 ScrollView ,你应该把它放在页脚布局之上( android:layout_above="@+id/idOfYourFooterLayout" )

试试这个:

<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="wrap_content"
   android:orientation="vertical">

  <ScrollView android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:id="@+id/sw_layout"
       android:layout_above="@+id/footer"
       android:orientation="vertical">
//your UI...
  </ScrollView>

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

      <Button
          android:id="@+id/btn_date"
          android:layout_height="35dp"
          android:padding="5dp"
          android:drawableLeft="@drawable/calendar"
          android:text="Tarih" />

      <Button
          android:id="@+id/btn_converter"
          android:layout_height="35dp"
          android:padding="5dp"
          android:drawableLeft="@drawable/calendar"
          android:text="Hesap" />
   </LinearLayout>
</RelativeLayout>

关于java - 将底部的线性布局固定为 android 中的页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17164916/

相关文章:

java - 基本 Java Swing - 在运行时添加带有图标的 JLabels

java - 从列表中删除重复项而不对其进行迭代或使用集合

java - 使用注释处理器创建具有特定注释的类列表

Java SWT - 在 shell 上使用 SWT.V_SCROLL 时 shell 的标题栏消失

Android日历 View 可滚动

android - 更新用户个人资料照片不会使用 currentUser.photoUrl 进行更新

Android - 当对象不可序列化或不可打包时将对象传递给 Activity

android - 如果布局扩展太大,按钮不会出现

android - 将 textView 和 editText 放在 android 应用程序的同一行

android - LinearLayout 在填充父级的 View 右侧添加元素