3

Currently i'm making my apps layout for t.v, the issue i'm facing is i have a recyclerview to show recent activity of user, in mobiles i have shown the recent activity vertically, but in android t.v we have more width then height so i want to show recent activity horizontally i have tried many solution's like

<android.support.v7.widget.RecyclerView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        tools:orientation="horizontal" tools:layoutManager="android.support.v7.widget.LinearLayoutManager" />

but it's still displaying in vertical i dont know why.. I also tried adding the recyclerview in a ScrollView but still not working., maybe i'm declaring LinearLayoutManager in java that's why it's showing in vertical format..

Code of my fragment where i'm inflating the reclerview

View view=inflater.inflate(R.layout.recent_activity_tab1_recycler_view, container, false);
        RecyclerView recent_activity_list = (RecyclerView) view.findViewById(R.id.recent_activity_list);
        recent_activity_list.setLayoutManager(new LinearLayoutManager(getActivity()));
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
shaheryar
  • 43
  • 6

2 Answers2

1

Don't give orientation there. Instead of that use layout manager for setting orientation of recyclerView.

For ex.

LinearLayoutManager layoutManager
    = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);

Here first param is context, second is orientation and third is reverseLayout.

You can change orientation there.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
The90sArtist
  • 177
  • 1
  • 1
  • 9
  • but if i give orientation horizontal here then my mobile shows recyclerview in horizontal, i want it responsive vertical for mobiles and horizontal for tv – shaheryar Nov 13 '18 at 09:01
0

try to replace this line

recent_activity_list.setLayoutManager(new LinearLayoutManager(getActivity()));

with this line

recent_activity_list.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
Hazem Ashraf
  • 310
  • 2
  • 8
  • have tried this too, but it sets the orientation horizontal for mobiles too, i want it vertical for mobiles and horizontal for tv – shaheryar Nov 13 '18 at 09:02
  • so you have to check first if device is Tv or phone and then use one of the layout[horizontal - vertical] you may find this answer helpful for checking https://stackoverflow.com/questions/27138838/how-can-i-check-if-an-app-is-running-on-an-android-tv – Hazem Ashraf Nov 13 '18 at 09:06