6

次のビュー階層で、Design Support Library 22.2.1 を使用します。

<DrawerLayout
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:fitsSystemWindows="true">
    <CoordinatorLayout
     android:layout_width="match_parent"
     android:layout_height="match_parent">
        <AppBarLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
            <Toolbar
             android:layout_width="match_parent"
             android:layout_height="?attr/actionBarSize" />
            <TabLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:clipToPadding="false"
             app:tabGravity="fill"
             app:tabMode="scrollable" />
        </AppBarLayout>
        <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">

            <!-- Fragments replaced here -->
            <LinearLayout
             android:orientation="vertical"
             android:layout_width="match_parent"
             android:layout_height="match_parent">
                <CustomDashboardView
                 android:layout_width="match_parent"
                 android:layout_height="120dp" />
                <ViewPager
                 android:layout_width="match_parent"
                 android:layout_height="match_parent">

                    <!-- Tab Fragments go here -->
                    <LinearLayout
                     android:orientation="vertical"
                     android:layout_width="match_parent"
                     android:layout_height="match_parent">
                        <CustomEmptyErrorLayout
                         android:layout_width="match_parent"
                         android:layout_height="match_parent"
                         android:visibility="gone" />
                        <android.support.v7.widget.RecyclerView
                         android:layout_width="match_parent"
                         android:layout_height="match_parent" />
                    </LinearLayout>

                </ViewPager>
            </LinearLayout>

        </FrameLayout>
    </CoordinatorLayout>
    <NavigationView
     android:layout_height="match_parent"
     android:layout_width="wrap_content"
     android:fitsSystemWindows="true" />
</DrawerLayout>

RecyclerView の高さがそれが含まれる表示領域よりも大きいというこの問題に遭遇したため、RecyclerView がオフスクリーンで描画されているように見え、RecyclerView の最後の項目をフル ビューにスクロールすることはできません。Toolbar や TabLayout に関する動きもありません (ただし、FrameLayout には layout_behaviour が適用されます)。

問題を強調した注釈付きのスクリーンショット

私はこれをバグとして報告しましたが、ol' Banesy はこれが意図したとおりに機能していると述べています。その場合、layout_height="match_parent" を尊重し、表示されている画面内にそのアイテムを描画する RecyclerView を優先して、この意図した動作を回避するにはどうすればよいですか? https://code.google.com/p/android/issues/detail?id=182391

更新: Design Support v23 では、まったく見栄えがよくありません。これをデザイン サポート ライブラリ自体に絞り込みました (つまり、デザイン サポート v22.2.1 を残しながら RecyclerView、appcompat などを v23 に更新すると、上記と同じ問題が発生します)。そのため、新しい外観である CustomDashboardLayout と RecyclerView は AWOL になりました。うまくいけば、これも意図したとおりに機能しません。

ここに画像の説明を入力

4

2 に答える 2

6

v23 でこれを修正し、v22.2.1 の回避策を見つけました。バージョン間で動作がまったく異なるという事実は、「意図したとおりに動作する」というのが完全な真実ではないと私に信じさせます。

v23 修正: ViewPager の上の CustomDashboardLayout が問題を引き起こしていました。visibility="gone" に強制されていない場合、ViewPager は階層にまったく追加されませんでした。それがなくなると、ViewPager が追加され、RecyclerView はその高さを正しくサイズ変更します。

v22.2.1 の回避策: v23 の修正は v22.2.1 には影響しません。回避策は RecyclerView で layout_marginBottom="?attr/actionBarSize" を設定することです。

とにかく終わってよかった。

于 2015-08-24T00:19:20.167 に答える