【发布时间】:2019-11-19 16:02:43
【问题描述】:
我想制作一个类似视图的电子表格来显示一些数据。到目前为止,这就是我所拥有的,但我一次只能滚动一种方式。我希望能够同时水平和垂直滚动。
现在我在水平滚动视图中有一个 recyclerView。
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/change_log_rv"
android:layout_width="wrap_content"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</HorizontalScrollView>
这是我的 recyclerView 行布局。
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/change_log_table_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true">
<TableRow>
<TextView
android:id="@+id/change_log_flavor_name"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:gravity="center_horizontal"
android:maxLines="3"
android:textSize="16sp"/>
<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="@android:color/darker_gray"/>
<TextView
android:id="@+id/change_log_batch_number"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:gravity="center_horizontal"
android:maxLines="3"
android:textSize="16sp"/>
<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="@android:color/darker_gray"/>
<TextView
android:id="@+id/change_log_date"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:gravity="center_horizontal"
android:maxLines="3"
android:textSize="16sp"/>
<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="@android:color/darker_gray"/>
<TextView
android:id="@+id/change_log_number_of_blocks"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:gravity="center_horizontal"
android:maxLines="3"
android:textSize="16sp"/>
<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="@android:color/darker_gray"/>
<TextView
android:id="@+id/change_log_time"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:gravity="center_horizontal"
android:maxLines="3"
android:textSize="16sp"/>
</TableRow>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@android:color/darker_gray"/>
</TableLayout>
这里是我用 Java 设置我的 recyclerView 的地方。
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
mChangeLogRv.setLayoutManager(layoutManager);
mInventoryChangeLogAdapter = new InventoryChangeLogAdapter(null, mFlavorKeyAndName, this);
mChangeLogRv.setAdapter(mInventoryChangeLogAdapter);
任何帮助将不胜感激。谢谢!
【问题讨论】:
-
这并不容易。您将不得不像这样编写自己的布局管理器:github.com/devunwired/recyclerview-playground/blob/master/app/… Dave Smith 在这里讨论了他是如何写的:wiresareobsolete.com/2014/09/… 他还在 youtube 上有一些关于它的视频。
标签: android android-recyclerview