2016-08-04 86 views
3

我正在使用工具:listitem属性在设计布局中使用recyclerview显示我的视图。问题是,它们总是出现在垂直列表中。有没有办法让设计布局编辑器水平显示它们?Android设计布局ListItem RecyclerView Horizo​​ntal

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.v7.widget.RecyclerView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:listitem="@android:layout/simple_list_item_checked"/> 

enter image description here

我想上述图像,水平显示。在设计视图中。不是在应用程序本身,我知道如何做到这一点。

+0

您可以阅读这篇文章[HTTP://blog.nkdroidsolutions。 com/android-horizo​​ntal-vertical-recyclerview-example /] – sonnv1368

+0

这是否有帮助:http://stackoverflow.com/questions/28460300/how-to-build-a-horizo​​ntal-listview-with-recyclerview? – Shaishav

+0

sonnv1368该链接无效。 Shaishav不,它不是,这个问题不是关于创建水平的回收站视图,而是关于在Android Studio的设计视图中显示它。 – easycheese

回答

19

请选中该代码

<android.support.v7.widget.RecyclerView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    app:layoutManager="android.support.v7.widget.LinearLayoutManager" /> 
+0

这不会在设计视图中水平显示。 – easycheese

+0

可以在这里发布xml和java代码 –

+1

结果如果你将它和工具结合起来:listitem =“@ layout/whatever”这个工作。 – easycheese

-2

是的。

当您使用RecyclerView时,您需要指定一个负责布局视图中每个项目的LayoutManager。 LinearLayoutManager允许您指定方向,就像正常的LinearLayout一样。

要创建具有RecyclerView水平列表,你可以做这样的事情:

LinearLayoutManager layoutManager 
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); 

RecyclerView myList = (RecyclerView) findViewById(R.id.my_recycler_view); 
myList.setLayoutManager(layoutManager); 
+0

你误解了这个问题。我指的是在Android工作室的设计视图 – easycheese

+0

它应该工作可以在这里发布xml和java代码 –

+0

您没有阅读我的评论。 Android工作室布局编辑器中的DESIGN VIEW。不是代码 – easycheese