【问题标题】:How to draw a horizontal list view in android and access it using a horizontal scroll view如何在android中绘制水平列表视图并使用水平滚动视图访问它
【发布时间】:2016-10-24 06:55:45
【问题描述】:

我在一个列表中有 n 个项目。即项目1,项目2,项目3 ..项目-n。我想通过单击按钮打开它们并以水平方式显示它们。例如

项目1项目2项目3......项目-N

如何在android的xml设计中绘制相同的。 请帮忙解决。

【问题讨论】:

标签: android listview


【解决方案1】:

像这样使用

xml 布局

<android.support.v7.widget.RecyclerView
     android:id="@+id/recyclerView_category"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:focusableInTouchMode="true"
     app:layout_behavior="@string/appbar_scrolling_view_behavior" />

在Activity类中使用:

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView_home_10);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(layoutManager);
// If using recylerview in srollview 
recyclerView.setNestedScrollingEnabled(false);
// set Adapter
recyclerView.setAdapter(adapter);

【讨论】:

    【解决方案2】:

    LayoutManager 是 RecyclerView 中布局视图的类。因此,如果要更改布局,请更改 recyclerView.setLayoutManager(LayoutManager)。在您的情况下,如果您使用 LinearLayoutManager,请通过调用:

    LinearLayoutManager layoutManager = ...
    recyclerView.setLayoutManager(layoutManager);
    
    //when you want horizontal
    layoutManager.setOrientation(context,LinearLayoutManager.HORIZONTAL,false);
    
    //when you want vertical
    layoutManager.setOrientation(context,LinearLayoutManager.VERTICAL,false);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-05
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-12
      相关资源
      最近更新 更多