Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.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 如何使用linearlayout创建类似gridview的数据视图_Android_Android Layout_Listview_Android Studio_Android Intent - Fatal编程技术网

Android 如何使用linearlayout创建类似gridview的数据视图

Android 如何使用linearlayout创建类似gridview的数据视图,android,android-layout,listview,android-studio,android-intent,Android,Android Layout,Listview,Android Studio,Android Intent,我写了一个代码,其中, 布局用权重和划分。 每个砝码都包含一个线性布局 我有一个字符串数组列表。 我必须把数据放在 > 1. 2. 3. > 4. 5. 提供一些代码或示例。 这显示了如何使用由字符串数组列表组成的适配器创建RecyclerView 特别是,这是您需要的代码: mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view); m

我写了一个代码,其中, 布局用权重和划分。 每个砝码都包含一个线性布局

我有一个字符串数组列表。 我必须把数据放在

> 1.         2.          3.
> 4.          5.
提供一些代码或示例。

这显示了如何使用由字符串数组列表组成的适配器创建RecyclerView

特别是,这是您需要的代码:

    mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);

    mLayoutManager = new GridLayoutManager(this, numberOfColumns);
    mRecyclerView.setLayoutManager(mLayoutManager);

    // specify an adapter (see also next example)
    mAdapter = new MyAdapter(myDataset); //Where myDataset is your ArrayList<String> and MyAdapter is described in depth in the link I provided
    mRecyclerView.setAdapter(mAdapter);

此外,LinearLayout不适合动态数据列表,即使理论上你可以在列表中循环并使用“addView”手动创建所有内容。

我不太明白问题到底是什么。。。。如果需要网格,请使用带有适配器的RecyclerView。适配器确实与ArrayList一起工作,所以如果这是您需要的,我将在答案中添加一些示例代码。特别是,LinearLayout适用于线性布局,而不是网格。您能帮助我禁用gridview滚动视图吗?如何使用线性布局作为gridview的替代方案?我的答案是否帮助您解决问题?记住接受您问题的答案。。。如果他们帮忙的话
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
p.weight = 1;

view.setLayoutParams(p);