Sunteți pe pagina 1din 2

9/24/2017 android - How to make the last footer fixed (ListView) - Stack Overflow

Learn, Share, Build


Each month, over 50 million developers come to Stack Overflow to Google Facebook
learn, share their knowledge, and build their careers. OR

Join the worlds largest developer community.

How to make the last footer fixed (ListView)

I have a ListView with 2 footer views. The first one is a bunch of TextView s, while the second one is a button. I'm trying to fix the second footer
so that it always shows at the bottom of the screen.

I tried the following:

1. alignParentBottom = true

2. layout_gravity="bottom"

3. footerView2.bringToFront()

And combinations of the above. But none of them worked out. How can I achieve this?

UPDATE

I shouldn't have added the View which I always want on the screen (fixed) as footer.

I just added the wannabe-fixed-view with the listView. Did alignParentBottom = true and also view.bringToFront() . It worked out for me.

android listview footer

edited Mar 7 '16 at 7:38 asked Mar 7 '16 at 7:21


Akeshwar Jha
2,243 2 17 54

This second footer will be visible and fixed when whole of the listview will be scrolled , right ? Prateek Mar
7 '16 at 7:24

Yeah, when the whole listview is scrolled, the first footer is scrolled... The second footer will always be
visible and fixed at the bottom. Akeshwar Jha Mar 7 '16 at 7:25

add layout_weight="1" in listview. Chirag Savsani Mar 7 '16 at 7:26

1 Don't use a footer if you want it to have a permanent, fixed location. Add another View below your
ListView as part of your layout file. PPartisan Mar 7 '16 at 7:27

1 @user5038993 was about to right the same as PPasrtisan. Prateek Mar 7 '16 at 7:28

3 Answers

Separate your ListView and bottom footer. The idea is:

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

<Button
android:id="@+id/btn_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Bottom button"/>

<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/btn_bottom"/>

</RelativeLayout>

https://stackoverflow.com/questions/35838225/how-to-make-the-last-footer-fixed-listview 1/2
9/24/2017 android - How to make the last footer fixed (ListView) - Stack Overflow

answered Mar 7 '16 at 7:31


yital9
2,879 8 30 49

yup, that was what I was missing. Clear point. I also had to use bringToFront . Akeshwar Jha Mar 7 '16
at 7:34

Create separate xml file which contain all textviews and button you want as footer part.Then
bind this xml as a footer of listview. You can binf footer with listview by this method:
listview.addFooterView(footerView);
For example:

View footerView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))


.inflate(R.layout.listviewfooter, null, false);
spDate = (Spinner) headerView.findViewById(R.id.spdate);
llDatepicker = (LinearLayout) headerView.findViewById(R.id.lldatepicker);
rvDatepicker = (RecyclerView) headerView.findViewById(R.id.rvdatepicker);
rvTimepicker = (RecyclerView) headerView.findViewById(R.id.rvtimepicker);

lvAddress.addFooterView(footerView);

answered Mar 7 '16 at 7:27


Parsania Hardik
2,372 1 15 31

If you are Trying to add a View which will be shown even if we scroll the List Up or
Down... u can do something like this. I had done this before But as a header.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/new_container"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="LOAD EARLIER MESSAGES"
android:id="@+id/loadMore"
android:background="#90F58220"
android:visibility="visible"/>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listContainer"
android:layout_below="@+id/loadMore"
android:layout_above="@+id/container">
<ListView
android:id="@+id/messagesContainer"
android:transcriptMode="normal"
android:dividerHeight="0dp"
android:divider="@null"
android:stackFromBottom="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</RelativeLayout>
<RelativeLayout
android:id="@+id/container"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:background="#ffffff"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:layout_height="wrap_content" >
</RelativeLayout>

The LoadMore Button is always visible on the Top of the List...


To add it to footer, Just Change

android:layout_below="@+id/loadMore"
android:layout_above="@+id/container"

to

android:layout_above="@+id/loadMore"

answered Mar 7 '16 at 7:33


Abhinash
133 10

https://stackoverflow.com/questions/35838225/how-to-make-the-last-footer-fixed-listview 2/2

S-ar putea să vă placă și