2

フリップボードのように、別の(グリッドのようRecyclerViewな) 下に (リストのような)を使用したいRecyclerView

ここに画像の説明を入力

RecyclerViewラップ コンテンツで 2 つの内部を試しScrollViewましたが、何も表示されません。

線形レイアウトに配置し、同じ重みを加えると、2 つのビューを見ることができます。しかし、それはこのアプリのビューのようには見えません。

これが私のレイアウトです

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/parent_category_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minWidth="@dimen/default_small_padding"
        android:gravity="center"
        android:visibility="visible"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/category_grid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:columnWidth="150dp"
        android:gravity="center"
        android:visibility="visible"/>

</LinearLayout>

4

3 に答える 3

3

実際には、たった 1 つの で目的のレイアウトを実現する非常に簡単な方法がありますRecyclerView

キーは aGridLayoutManagerとそのを使用していSpanSizeLookupます。まず、次のように GridLayoutManager を定義します。

GridLayoutManager layoutManager = new GridLayoutManager(context, spanCount);

ここで、spanCount は、必要なスパン/列の最大量です。あなたの場合、 spanCount は2でなければなりません。

ここで、この layoutManager に項目がスパンする必要があるスパン数を伝える方法が必要です。簡単な方法は、1 つの列だけにまたがる項目にはビュータイプ/ViewHolder を使用し、幅全体にまたがる項目には別のビュータイプ/ViewHolder を使用することです。

グリッドアイテムのビュータイプを として定義し、VIEWTYPE_GRID_ITEM標準リストアイテムのビュータイプを として定義するとしますVIEWTYPE_LIST_ITEM。次に、これらのビュータイプを使用して、1 つのスパンのみをいつ使用するかを layoutManager に伝えることができます。

layoutManager.setSpanSizeLookup(new SpanSizeLookup() {
    @Override
    public int getSpanSize(int position){
        return adapter.getItemViewType(position) == VIEWTYPE_GRID_ITEM ? 1 : spanCount;
    }
});

最後に、layoutManager を RecyclerView に設定します。

recyclerView.setLayoutManager(layoutManager);

以上です!

于 2015-08-28T12:13:45.777 に答える
0

Android では、一度に 1 つのスクロール可能なビューのみを使用することをお勧めします。1 つのスクロール可能なビューを別のビュー内で使用する場合は、以下のリンクを参照してください。

1)スクロール ビュー内の Android リスト ビュー

2) https://stackoverflow.com/questions/6210895/listview-inside-scrollview-is-not-scrolling-on-android

于 2015-08-28T10:48:18.027 に答える