Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使水平滚动视图具有4列&;基于动态数据的2行?_Android_Android Studio_Android Layout - Fatal编程技术网

Android 如何使水平滚动视图具有4列&;基于动态数据的2行?

Android 如何使水平滚动视图具有4列&;基于动态数据的2行?,android,android-studio,android-layout,Android,Android Studio,Android Layout,我需要2行4列。如果有10个项目,那么将首先显示8个项目,然后水平滚动视图时将显示剩余的2个项目(第二个视图将只有2个项目)。项目的数量将根据api响应动态添加 您可以尝试使用RecyclerView int numberOfColumns = 4; recyclerViewOBJ.setLayoutManager(new GridLayoutManager(this, numberOfColumns)); 或 //您可以设置文本元素 RecyclerView.LayoutM

我需要2行4列。如果有10个项目,那么将首先显示8个项目,然后水平滚动视图时将显示剩余的2个项目(第二个视图将只有2个项目)。项目的数量将根据api响应动态添加

您可以尝试使用RecyclerView

    int numberOfColumns = 4;
    recyclerViewOBJ.setLayoutManager(new GridLayoutManager(this, numberOfColumns));


//您可以设置文本元素

RecyclerView.LayoutManager llm=新的GridLayoutManager(活动,3);binding.rv.setLayoutManager(llm);这是我的代码。但无法水平滚动。对于水平滚动,您可以访问@TruptiNasit是否有任何解决方案?水平滚动视图下的GridLayout对我不起作用。因此保持GridRecyclerView不变&禁用其垂直滚动。然后在recyclerview上添加了touch listener来检测左右滑动,然后在那里执行我的任务。
    int numberOfColumns = 4;
    recyclerViewOBJ.setLayoutManager(new GridLayoutManager(this, numberOfColumns));
<HorizontalScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     >

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:columnCount="4"
        android:rowCount="2"
        android:orientation="horizontal" >

         // You can set Text Element

    </GridLayout>

 </HorizontalScrollView>