Android RecyclerView提供垂直和水平

时间:2016-04-21 11:30:47

标签: android scrollview android-recyclerview

我有一个Vertical RecyclerView。我已在其中添加了项目。它工作正常。现在我的问题是当任何一个项目有这么多数据时,我希望我的整个RecyclerView水平滚动而不是那个单项。

这是我制作的用户界面。 enter image description here

对于Inner cell,我在Linearlayout中动态添加视图。

for (int i = 0; i <subItem ; i++) {

        View Cv= Li.inflate(R.layout.custom_cell, holder.ViewLayout, false);
        TextView  textBedInfo = (TextView) Cv.findViewById(R.id.textBedInfo);
        TextView  textRowInfo = (TextView) Cv.findViewById(R.id.textRowInfo);

        textBedInfo.setTypeface(fontBold);
        textRowInfo.setTypeface(fontRegular);

        if(i==0 || i==subItem-1){
            textBedInfo.setVisibility(View.GONE);
            textRowInfo.setText((position+1)+" Row");
        }
        else{
            textRowInfo.setVisibility(View.GONE);
            ConstantMethod.setBorder(textBedInfo, Color.WHITE,R.drawable.circle);
            textBedInfo.setText(String.valueOf(i));
        }
        holder.ViewLayout.addView(Cv);
    }

正如你在图片中看到的那样,最后一行有太多的数据,所以我希望我的回收站视图水平滚动,但它不起作用。

我尝试将HorizontalScrollView设为recyclerView的父级,但它也无效。它显示空白视图。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:gravity="center_horizontal"
          tools:context="com.sunbed.reservation.ReservationMapFragment">


<android.support.v7.widget.RecyclerView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:id="@+id/recyclerMaps"
    app:layoutManager="LinearLayoutManager">

</android.support.v7.widget.RecyclerView>

这是我的主要布局。任何人都可以帮助我吗?

感谢。

1 个答案:

答案 0 :(得分:0)

最后我设法实现了它。我删除了resyclerview。并使用了Scrollview。我在scrollview中动态添加了所有视图。这是我添加了视图的父布局。

<ScrollView
    android:id="@+id/scrollViewMap"
    android:clipToPadding="false"
    android:layout_width="wrap_content"
    android:scrollbars="none"
    android:layout_height="wrap_content">
    <HorizontalScrollView
        android:layout_width="wrap_content"
        android:scrollbars="none"
        android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/layoutMaps"
            android:layout_width="wrap_content"
            android:gravity="center"
            android:layout_height="wrap_content"
            android:orientation="vertical">

        </LinearLayout>
    </HorizontalScrollView>
</ScrollView>

我知道,在动态加载所有视图时加载视图需要一些时间。但是现在我使用了这个解决方案。总是接受更好的答案。 感谢。

相关问题