android - RecyclerView with fixed column and header, plus scrollable footer -


i trying find way implement standing table sports app (like nba game time standings), fixed header, fixed first column , footer. searched bit on how it, best shot project (https://github.com/inqbarna/tablefixheaders) uses own view instead of recycler of gridview. knows or knows how can start (adapter or layoutmanager)?

edit (adding images)

initial state

scrolled state showing footer

after testing , searching lot, implemented own, combining listview inner horizontalscrollviews.

first, extended horizontalscrollview report me scroll event, adding listener:

public class myhorizontalscrollview extends horizontalscrollview {      private onscrolllistener listener;      @override     protected void onscrollchanged(int l, int t, int oldl, int oldt) {         super.onscrollchanged(l, t, oldl, oldt);         if (listener != null) listener.onscroll(this, l, t);     }      public void setonscrolllistener(onscrolllistener listener) {         this.listener = listener;     }      public interface onscrolllistener {         void onscroll(horizontalscrollview view, int x, int y);     }        } 

then, created layout linearlayout, containing header , listview activity (or fragment, if it's need).

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical">      <include         android:id="@+id/header"         layout="@layout/header" />      <listview         android:id="@+id/list"         android:layout_width="match_parent"         android:layout_height="match_parent" /> </linearlayout> 

each item of list linearlayout, textview (the fixed column) , horizontalscrollview. layout of both header , lines following:

<?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:orientation="horizontal">      <textview         style="?android:attr/textappearancemedium"         android:background="#f00"         android:minwidth="40dp"         android:layout_width="wrap_content"         android:layout_height="wrap_content" />      <view         android:layout_width="1px"         android:layout_height="match_parent"         android:background="@android:color/black" />      <net.rafaeltoledo.example.myhorizontalscrollview         android:id="@+id/scroll"         android:scrollbars="none"         android:layout_width="match_parent"         android:layout_height="match_parent">          <linearlayout             android:layout_width="wrap_content"             android:layout_height="match_parent"             android:orientation="horizontal">              <!-- childs, or columns -->          </linearlayout>      </net.rafaeltoledo.example.myhorizontalscrollview>  </linearlayout> 

the trick scroll of eventbus (i used greenrobot's one) fire horizontal scroll event , move scrollers one. event object contains same data listener class (maybe can use listener object itself?)

public static class event {      private final int x;     private final int y;     private final horizontalscrollview view;      public event(horizontalscrollview view, int x, int y) {         this.x = x;         this.y = y;         this.view = view;     }      public int getx() {         return x;     }      public int gety() {         return y;     }      public horizontalscrollview getview() {         return view;     } } 

the list adapter class receives listener set in horizontalscrollview of each item.

public static class adapter extends baseadapter {      private final context context;     private myhorizontalscrollview.onscrolllistener listener;      public adapter(context context, myhorizontalscrollview.onscrolllistener listener) {         this.context = context;         this.listener = listener;     }      @override     public int getcount() {         return 30;     }      @override     public object getitem(int position) {         return new object();     }      @override     public long getitemid(int position) {         return position;     }      @override     public view getview(int position, view convertview, viewgroup parent) {         if (convertview == null) {             convertview = layoutinflater.from(getcontext()).inflate(r.layout.header, parent, false);             myhorizontalscrollview scroll = (myhorizontalscrollview) convertview.findviewbyid(r.id.scroll);             scroll.setonscrolllistener(listener);         }         return convertview;     }      public context getcontext() {         return context;     } } 

before continue, registered myhorizontalscrollview eventbus, adding eventbus.getdefault().register(this) each version of constructor, , added receiver method it:

public void oneventmainthread(mainactivity.event event) {     if (!event.getview().equals(this)) scrollto(event.getx(), event.gety()); } 

that scroll received position, if not fired scroll event.

and finally, setted in oncreate() method of activity:

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.list);      myhorizontalscrollview.onscrolllistener listener = new myhorizontalscrollview.onscrolllistener() {         @override         public void onscroll(horizontalscrollview view, int x, int y) {             log.d("scroll event", string.format("fired! %d %d", x, y));             eventbus.getdefault().post(new event(view, x, y));         }     };      listview listview = (listview) findviewbyid(r.id.list);      viewgroup header = (viewgroup) findviewbyid(r.id.header);     header.getchildat(0).setbackgroundcolor(color.white);     header.setbackgroundcolor(color.blue);     ((myhorizontalscrollview) header.findviewbyid(r.id.scroll)).setonscrolllistener(listener);      listview.setadapter(new adapter(this, listener));     listview.addfooterview(getlayoutinflater().inflate(r.layout.footer, listview, false)); } 

(please ignore weird coloring, it's better viewing what's happening).

and ta-daa, here desired result!

final result


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -