android - Change LayoutManager depending on device format -


i have recyclerview list of cards. want know whether it's possible change recyclerview's layoutmanager linear, when using phone, , staggeredgrid, when using tablet, programmatically. initial idea have same code on activity, , change layout.xml, given android uses different layoutmanagers, seems note complicated that. tried using cardslib library, got reeeaally confused documentation, since there no complete example custom cards. ideas?

yes possible. 1 solution define boolean resource in values folder. example, can define:

<bool name="is_phone">true</bool> 

in values folder , in values-sw720dp , values-sw600dp add same resource false.

<bool name="is_phone">false</bool> 

then, in activity's oncreate(), can this:

    boolean isphone = getresources().getboolean(r.bool.is_phone);      if (isphone) {         // set linearlayoutmanager recyclerview.     } else {         // set staggeredgridlayoutmanager recyclerview.     } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -