Android layout similar to Google Now

1.9k views Asked by At

I'm having trouble deciding the best route to take for the layout I want for my application. My thought is to have something very similar to Google Now's layout where it's a list of different types of cardviews that scroll with the entire page. In my app I would have 3 card types, the 1st one which is static and fixed. The 2nd one which is static but scrolls with the page. And the 3rd which can have "n" cards which all scroll with the page.

My app layout Every element in the 3rd card type will respond to a click event, which will launch a new fragment, and a long press event which I would like to eventually make the items actionable to both remove and rearrange certain elements.

Problem is, I don't know the best practice to achieve my desired layout. Should I do it with my RecyclerView's adapter using different ViewHolders? Going down that route seems like it would get messy pretty quick. One app that comes to mind that does something similar is Google Now which has the persistent search bar at the top.

Any tips to get me going in the right direction are appreciated.

Edit: The most promising lead I found to achieve what I want comes from Is there an addHeaderView equivalent for RecyclerView?. But my question is, how do I access the View, which would become my header, from my Fragment? From the looks of the code I basically let the Adapter inflate the view instead of the Fragment.

1

There are 1 answers

1
Andy Ho On

Sorry, i didn't test much with Google Now, but for the Layout you can follow the instruction below :

  • Root : LinearLayout (Vertical Mode) with 2 child
    1, RelativeLayout : layout for static card, no scroll, always be visible on the top
    2, ScrollView : Layout for other scolling view below the static, non-scroll layout. has a child is a LinearLayout (Vertical)

The drop-down layout and the list card layout, use can create it by genarating the views with a layout in code, and add them into only-child of scrollview (LinearLayout), or use a ListView with the height must be set to the max height of this list view with all child height calculated.