【发布时间】:2017-09-15 12:06:17
【问题描述】:
我已经用 GridLayoutManager 实现了一个 RecyclerView,它同时具有 Vertical 和 Horizontal Scroll ,我需要将布局滚动到特定位置,引用了许多代码,但对我来说并没有成功。
Java 类代码:
void RackGen()
{
STRarray = (String[]) mStringList.toArray(new String[mStringList.size()]);
ROWarray = (String[]) mRowList.toArray(new String[mRowList.size()]);
numcol = Integer.parseInt(col);
numdata = Integer.parseInt(num);
rv = (RecyclerView) findViewById(R.id.rview);
int numberOfColumns = numcol;
GridLayoutManager GM2 = new GridLayoutManager(this,numberOfColumns);
rv.setLayoutManager(GM2);
rv.setNestedScrollingEnabled(true);
rv.setHasFixedSize(true);
adapter = new MyRecyclerViewAdapter(this, STRarray, ROWarray);
rv.setAdapter(adapter);
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:layout_centerHorizontal="true"
android:id="@+id/llzoom"
android:orientation="vertical"
>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none"
android:overScrollMode="never">
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rview">
</android.support.v7.widget.RecyclerView>
</HorizontalScrollView>
</ScrollView>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
只有在添加嵌套滚动视图以及垂直和水平滚动后,滚动才能在两个方向上顺利进行。 现在我需要滚动到特定位置。
谢谢
【问题讨论】:
标签: android android-layout scroll android-recyclerview gridlayoutmanager