Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.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 listview在我的代码中垂直显示,是否可以更改为水平?_Android_Listview - Fatal编程技术网

Android listview在我的代码中垂直显示,是否可以更改为水平?

Android listview在我的代码中垂直显示,是否可以更改为水平?,android,listview,Android,Listview,我在布局中实现了一个listview: <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent"> </ListView> MyAdapter处理getView并垂直显示列表: images1 images2 .... 它可以水平显示列表吗?这样: image1 image2 ..

我在布局中实现了一个listview:

<ListView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</ListView>
MyAdapter处理getView并垂直显示列表:

images1
images2
....
它可以水平显示列表吗?这样:

image1  image2  ....
(当然,它应该可以滚动并显示所有图像)


我看到这个结果可以通过使用RecycleView和LayoutManager来实现,它以水平作为参数,但是我已经实现了ListView,它没有“setLayoutManager”方法。我需要它为API 15及以上版本工作。

尝试使用
方向

<ListView
    android:id="@+id/listView"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</ListView>

您可以尝试使用RecyclerView:

public class MyActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_activity);

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

    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    recyclerView.setLayoutManager(layoutManager);

    MyAdapter adapter = new MyAdapter(myDataset);
    recyclerView.setAdapter(adapter);
}
}

和布局为my_recycler_view.xml

<android.support.v7.widget.RecyclerView
    android:id="@+id/my_recycler_view"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>


ListView没有我注意到的方向,而且它对我不起作用:\噢,好的,我知道了。抱歉..请尝试RecyclerView-RecyclerView小部件是ListView更高级、更灵活的版本
<android.support.v7.widget.RecyclerView
    android:id="@+id/my_recycler_view"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>