【问题标题】:Not Able To align Footer at bottom of screen?无法在屏幕底部对齐页脚?
【发布时间】:2017-04-28 04:32:16
【问题描述】:

我无法在屏幕底部对齐页脚。我使用了相对布局,其中 android:layout_alignParentBottom="true" 但布局未显示在屏幕底部.

loan_collection_layout

  <?xml version="1.0" encoding="utf-8"?>

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


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

        <include layout="@layout/appbar_layout" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:background="#156B7A"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="125dp"
                android:text="Branch Office : Dhankuta"
                android:textColor="#FFFFFF"
                android:textSize="10sp" />

            <View
                android:layout_width="1dp"
                android:layout_height="13dp"
                android:layout_gravity="center"
                android:layout_marginLeft="5dp"
                android:background="#FFFFFF" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="5dp"
                android:text="Tuesday -4 April,2017"
                android:textColor="#FFFFFF"
                android:textSize="10sp"


                />

        </LinearLayout>


        <!-- Loan collection  -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_marginLeft="10dp"
            android:orientation="horizontal"
            android:weightSum="1">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Loan Collection"
                android:textColor="#2493A7"
                android:textSize="15sp"
                android:textStyle="bold" />

            <ImageView
                android:layout_width="12dp"
                android:layout_height="12dp"
                android:layout_gravity="center"
                android:layout_marginLeft="120dp"
                android:layout_marginRight="2dp"
                android:src="@mipmap/filter" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="15dp"
                android:layout_gravity="center"
                android:text="Filter"
                android:textSize="12sp"
                android:textStyle="normal" />

            <View
                android:layout_width="1dp"
                android:layout_height="15dp"
                android:layout_gravity="center"
                android:layout_marginLeft="5dp"
                android:background="#98A6A9" />

            <ImageView
                android:layout_width="12dp"
                android:layout_height="12dp"
                android:layout_gravity="center"
                android:layout_marginLeft="10dp"
                android:layout_weight="0.01"
                android:src="@mipmap/search" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="15dp"
                android:layout_gravity="center"
                android:layout_marginLeft="5dp"
                android:text="Search"
                android:textSize="12sp"
                android:textStyle="normal" />


        </LinearLayout>


        <!-- Linear Layout for 2nd Linear Layout -->

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:orientation="horizontal">


            <!-- 2nd liner layout ist column  -->

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/border"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="12dp"
                    android:layout_gravity="center"
                    android:layout_marginTop="7dp"
                    android:src="@mipmap/center" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:text="Center:005"
                    android:textSize="10sp" />


            </LinearLayout>

            <View
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.03"
                android:background="#FFFFFF" />


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:background="@drawable/border"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="12dp"
                    android:layout_gravity="center"
                    android:layout_marginTop="7dp"
                    android:src="@mipmap/group" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:text="Group"
                    android:textSize="10sp" />


            </LinearLayout>


            <View
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.03"
                android:background="#FFFFFF" />

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:background="@drawable/border"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="12dp"
                    android:layout_gravity="center"
                    android:layout_marginTop="7dp"
                    android:src="@mipmap/loan_type" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:text="Loan Type"
                    android:textSize="10sp" />


            </LinearLayout>

            <View
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.03"
                android:background="#FFFFFF" />

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:background="@drawable/border"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="12dp"
                    android:layout_gravity="center"
                    android:layout_marginTop="7dp"
                    android:src="@mipmap/date" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:text="Date:"
                    android:textSize="10sp" />


            </LinearLayout>

            <View
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.03"
                android:background="#FFFFFF" />

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:background="@drawable/border"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="12dp"
                    android:layout_gravity="center"
                    android:layout_marginTop="7dp"
                    android:src="@mipmap/valuedate" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:text="value date:"
                    android:textSize="10sp" />


            </LinearLayout>

        </LinearLayout>   <!-- Linear Layout 2nd ends Here -->


        <!-- Linear Layout for Group code starts here-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:orientation="horizontal">

            <CheckBox
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_gravity="center"
                android:layout_marginRight="5dp"
                android:buttonTint="#000000" />


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/border_loan_collection">

                <TextView


                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Group Code"
                    android:textColor="#333333"
                    android:textSize="12sp"
                    android:textStyle="bold" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/border_loan_collection">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Member No."
                    android:textColor="#333333"
                    android:textSize="12sp"
                    android:textStyle="bold" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/border_loan_collection">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Member Name"
                    android:textColor="#333333"
                    android:textSize="12sp"
                    android:textStyle="bold" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/border_loan_collection">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Remain Price"
                    android:textColor="#333333"
                    android:textSize="12sp"
                    android:textStyle="bold" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/border_loan_collection">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Total"
                    android:textColor="#333333"
                    android:textSize="12sp"
                    android:textStyle="bold" />

            </LinearLayout>


        </LinearLayout>

        <!-- 3rd layout starts here -->

        <!-- After third layout you have yo add listView in here and listitem should be populated through the JSON Data -->


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:orientation="horizontal">

            <CheckBox
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_gravity="center"
                android:layout_marginRight="5dp"
                android:buttonTint="#333333"
                android:checked="true" />


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#F3F3F3">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="001"
                    android:textSize="12sp"
                    android:textStyle="normal" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#F3F3F3">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text=" 001"
                    android:textSize="12sp"
                    android:textStyle="normal" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#F3F3F3">

                <TextView
                    android:id="@+id/textView"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Bimala Rai"
                    android:textSize="12sp"
                    android:textStyle="normal" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#F3F3F3">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="0.00"
                    android:textSize="12sp"
                    android:textStyle="normal" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#F3F3F3">

                <TextView

                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="0.00"
                    android:textSize="12sp"
                    android:textStyle="normal" />

            </LinearLayout>


        </LinearLayout><!-- 3rd layout ends here-->


        <!-- Linear Layout 4th starts here-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"

            android:orientation="horizontal">

            <CheckBox
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_gravity="center"
                android:layout_marginRight="5dp"
                android:buttonTint="#333333" />


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/border_loan_collection">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="001"
                    android:textColor="#333333"
                    android:textSize="12sp"
                    android:textStyle="normal" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/border_loan_collection">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="001"
                    android:textColor="#333333"
                    android:textSize="12sp"
                    android:textStyle="normal" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/border_loan_collection">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Uranus"
                    android:textColor="#333333"
                    android:textSize="12sp"
                    android:textStyle="normal" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/border_loan_collection">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="0.00"
                    android:textColor="#333333"
                    android:textSize="12sp"
                    android:textStyle="normal" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/border_loan_collection">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="0.00"
                    android:textColor="#333333"
                    android:textSize="12sp"
                    android:textStyle="normal" />

            </LinearLayout>


        </LinearLayout>  <!-- 4th linear layout ends here -->




        <!-- Total Bottom Layout starts herel -->

        <!-- Footer aligned to bottom -->

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_alignParentBottom="true"
            android:text="Footer"
            android:textColor="#000000"
            android:textSize="20sp" />



    </LinearLayout>

</RelativeLayout>

页脚如何显示在屏幕底部??

【问题讨论】:

  • android:gravity="bottom"android:layout_gravity="bottom" 用于RelativeLayout
  • 不工作@piyush
  • 将文本视图(页脚视图)放在父相对布局的结束标记之前

标签: android android-relativelayout


【解决方案1】:

您的主视图是 LinearLayout,它的工作方式与您尝试的方式不同。

为了获得您想要的结果,您需要将主布局设置为相对布局,然后将底部对齐设置为您的页脚。

例如:-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

    <!-- place all your view inside this layout-->

    </LinearLayout>

       <!--place your footer here with align bottom property set to true-->

         <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_alignParentBottom="true"
            android:text="Footer"
            android:textColor="#000000"
            android:textSize="20sp" />
</RelativeLayout/>

这个 sn-p 应该让你继续前进。

【讨论】:

  • 将文本视图(页脚视图)放在父相对布局的结束标记之前
  • 实际上父相对布局内的线性布局在您的情况下是无用的。您可以通过RelativeLayout 属性来实现它,例如android:layout_below="@+id/view_id"
  • @AldrinMathew 是的,他本可以做到的。但我给了他最可行的解决方案,减少与他合作
【解决方案2】:

您有两个选择,要么遵循@Anirudh Sharma 的回答,要么将RelativeLayout 的高度设为match_parent

【讨论】:

    【解决方案3】:

    您的父线性布局将按照您在布局中提供的方向依次堆叠您的视图,一个接一个。 android:layout_alignParentBottom="true" 仅适用于在 RelativeLayout 中定义的视图,而不是您定义的视图。

    将您的父布局设置为 RelativeLayout 而不是 LinearLayout,它会非常适合您!

    【讨论】:

      【解决方案4】:

      在页脚上方添加以下内容

      <View
                  android:layout_weight="1"
                  android:layout_width="match_parent"
                  android:layout_height="0dp" />
      

      【讨论】:

      • @Ghimire,我不确定这是否是最好的解决方案,但我已经多次使用过这个技巧,它对我很有效。
      • 它也适用于我。但它是替代解决方案。
      【解决方案5】:

      问题是 AlignParentBottom 仅在视图位于相对布局内时才有效。您的 Textview 位于线性布局内。将其放在线性布局之外和父级相对布局内。

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
      
        <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">
      
          <include layout="@layout/appbar_layout" />
      
          <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="25dp"
              android:background="#156B7A"
              android:orientation="horizontal">
      
             .
             .
             .
             .
        </LinearLayout> 
      
          <!-- Make sure your View is directly the child of Relative layout to use 
          alignParentBottom="true" -->
      
      
      
          <!-- Footer aligned to bottom  -->
      
          <TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_margin="5dp"
              android:layout_alignParentBottom="true"
              android:text="Footer"
              android:textColor="#000000"
              android:textSize="20sp" />
      
      
      
      </RelativeLayout>
      

      【讨论】:

        【解决方案6】:

        试试这个:

         <RelativeLayout
                        android:id="@+id/rl"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                <LinearLayout 
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">
                    <RelativeLayout
                        android:id="@+id/footer"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:background="#6AED83"
                        android:gravity="center" >
        
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="5dp"
                            android:text="Footer"
                            android:textColor="#000000"
                            android:textSize="20sp" />
                    </RelativeLayout>
                </LinearLayout>
            </RelativeLayout>
        

        【讨论】:

          【解决方案7】:

          试试下面的代码,它会起作用的

          <?xml version="1.0" encoding="utf-8"?>
          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical">
              <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="0dp"
                  android:orientation="vertical"
                  android:layout_weight="1">
          //Your other code will be here
              </LinearLayout>
          
              <TextView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_margin="5dp"
                  android:text="Footer"
                  android:layout_gravity="center"
                  android:textColor="#000000"
                  android:textSize="20sp" />
          </LinearLayout>
          

          【讨论】:

            【解决方案8】:
            Whatever you want in footer make sure you write code inside main parent layout(Relative layout) so u sill set android:layout_alignParentBottom="true"
            and it will remain all the time
            
            .Note that write that code just above the </RelativeLayout> (Closing of main parent layout ). So footer never get hidden by any other layout.
            

            【讨论】:

              猜你喜欢
              • 2013-04-29
              • 1970-01-01
              • 2013-08-19
              • 1970-01-01
              • 2021-01-11
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2011-11-24
              相关资源
              最近更新 更多