11

I needed to implement a layout which is similar to Google Chrome's stack of tabs as shown below .

Are there any libraries available for this ?

enter image description here

davidvarghese
  • 637
  • 2
  • 10
  • 18
  • 2
    Have a look here (http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/5.L_preview/com/example/android/home/ApplicationsStackLayout.java#ApplicationsStackLayout) This is the view that is used in Android Home Activity – hoomi Sep 12 '14 at 14:34
  • @hoomi ApplicationsStackLayout is just a viewgroup which lays its child views one by one either horizontally or vertically...I need a viewgroup which stacks the child views like a deck of cards plus scrolling effects like in Chrome android browser...Thanks for the link to Android L home screen....But any idea how they achieve the Chrome tabs like interactions in that?? – davidvarghese Sep 17 '14 at 12:00
  • Did u find a solution for your problem? Because I'm trying to implement the same thing and I'm not finding any example... :-( – michoprogrammer Apr 26 '16 at 14:30

2 Answers2

1

You need to create a set custom drawables for each aspect of the card and use them in the layout. You can use table layout for this purpose.

For example to put a background with corners you can create a drawable as follows:

Add new drwabe resource as follows:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
   android:shape="rectangle" >
   <corners android:radius="5dp"/>
   <stroke android:width="1dp" android:color="choose the color which you want"/>
   <padding android:top="10dp" android:left="10dp" android:bottom="10dp" 
      android:right="10dp"/>
</shape>

Create a custom style and use the above drawable as background:

<style name="ContactTextView">
      <item name="android:background">@drawable/drawableName</item>
      // add other items 
</style>

Apply the style on each item in your layout

Nipun Anand
  • 479
  • 2
  • 6
  • Thanks..Btw its not just about setting UI properties of the views . Chrome has a very elegant user gestures for interacting with the tabs...eg: User can swipe down the entire view with varying displacements for each items , ie , the entire list acts like a physical deck of cards . And I think there lies the main implementation challenge – davidvarghese Sep 15 '14 at 04:19
1

Use a RecyclerView with your own LayoutManager. The layoutmanager can than stack it like this. To implement behaviour (like expanding an item on click) you need more code. I coudlnt find an open source project which has this.

Have a look here for help:

http://wiresareobsolete.com/2014/09/building-a-recyclerview-layoutmanager-part-1/

http://wiresareobsolete.com/2014/09/recyclerview-layoutmanager-2/

http://wiresareobsolete.com/2015/02/recyclerview-layoutmanager-3/

TjerkW
  • 2,086
  • 21
  • 26