0

I have layout with ListView. I need to add HeaderView and FooterView to that ListView. I have added HeaderView and FooterView. FooterView not showing fully.

HeaderView:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:scaleType="fitXY"
    android:src="@drawable/giftcard_banner" />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right|center"
    android:layout_marginRight="20dip"
    android:src="@drawable/loyalty_card" />
   </FrameLayout>

FooterView:

 <?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="wrap_content"
android:background="@color/snow_white_light"
android:orientation="vertical">

<TextView
    android:id="@+id/txtSimilarShops"
    style="@style/SimpleTextViewSmall"
    android:layout_gravity="left|top"
    android:background="@color/blue"
    android:gravity="left|center"
    android:padding="10dip"
    android:text="Similar Shops"
    android:textColor="@color/White" />

    <android.support.v7.widget.RecyclerView
     android:id="@+id/recyclerView"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:scrollbars="horizontal"
     android:visibility="visible" />
   </LinearLayout>

Java: I have added like this but RecyclerView not showing.

 View headerView = getLayoutInflater().inflate(R.layout.header, null);
 listRewards.addHeaderView(headerView);
 View footerView = getLayoutInflater().inflate(R.layout.footer, null);
 txtSimilarShops = (TextView) footerView.findViewById(R.id.txtSimilarShops);
 recyclerView = (RecyclerView) footerView.findViewById(R.id.recyclerView);
 LinearLayoutManager layoutManager = new LinearLayoutManager(RewardsDetails.this);
 layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
 recyclerView.setLayoutManager(layoutManager);
 listRewards.addFooterView(footerView);

Is it possible to add recycler view in listview's footer. Please suggest your ideas. Thanks

Murali Ganesan
  • 2,925
  • 4
  • 20
  • 31
  • Does this answer your question? [How do I make WRAP\_CONTENT work on a RecyclerView](https://stackoverflow.com/questions/27475178/how-do-i-make-wrap-content-work-on-a-recyclerview) – The Dreams Wind Nov 23 '22 at 21:31

1 Answers1

1

Edit:

Information in this answer is no longer relevant. Please refer to this answer for up-to-date solution.


It happens because the RecyclerView layout cannot just deduce its content size, and android:layout_height="wrap_content" is not quite applicable to this class.

However you may provide a custom LayoutManager to handle this scenario.

The Dreams Wind
  • 8,416
  • 2
  • 19
  • 49