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
Post a Comment