How to build a Horizontal ListView with RecyclerView?

前端 未结 13 1042
小鲜肉
小鲜肉 2020-11-22 04:53

I need to implement a horizontal listview in my Android application. I did a bit of research and came across How can I make a horizontal ListView in Android? and Horizontal

13条回答
  •  醉酒成梦
    2020-11-22 05:40

    It's for both for Horizontal and for Vertical.

    RecyclerView recyclerView;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_test_recycler);
        recyclerView = (RecyclerView)findViewById(R.id.recyclerViewId);
    
        RecyclAdapter adapter = new RecyclAdapter();
    
        //Vertical RecyclerView
        RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
        recyclerView.setLayoutManager(mLayoutManager);
    
        //Horizontal RecyclerView
        //recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext(),LinearLayoutManager.HORIZONTAL,false));
    
        recyclerView.setAdapter(adapter);
    
    }
    

提交回复
热议问题