Recyclerview with both vertical and horizontal scrolling

Viewed 402

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()));
2 Answers

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.

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));
Related