无法在屏幕底部对齐页脚?

Not Able To align Footer at bottom of screen?

我无法对齐底部的页脚 screen.I 使用了 RelativeLayout 其中 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>

How can footer be displayed at bottom of screen??

您的主视图是 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/>

这段代码应该可以让你继续。

你有两个选择,要么按照@Anirudh Sharma 的回答,要么让你的 RelativeLayout 的身高达到 match_parent

试试这个:

 <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>

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

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

在页脚上方添加以下内容

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

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

<?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>

问题是 AlignParentBottom 仅在视图位于相对布局内时才有效。您的 Textview 在线性布局内 Layout.Put 它在线性布局之外和父相对布局内。

<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>
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.