str*_*aya 3 android android-recyclerview androiddesignsupport android-coordinatorlayout
使用具有以下视图层次结构的设计支持库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>
Run Code Online (Sandbox Code Playgroud)
我遇到了一个问题,其中RecyclerView的高度大于应包含该可见区域的可见区域,因此RecyclerView看起来像在屏幕外绘制,并且不可能将RecyclerView中的最后一项滚动到完整视图。关于工具栏和TabLayout也没有任何变化(尽管layout_behaviour应用于FrameLayout)。
我曾将其报告为错误,但是ol'Banesy表示这已按预期进行。如果是这种情况,我如何避免这种预期的行为,而使用RecyclerView,它尊重layout_height =“ match_parent”并在可见屏幕内绘制其项目?https://code.google.com/p/android/issues/detail?id=182391
更新:现在有了Design Support v23,它看起来一点也不好。我将范围缩小到Design Support库本身(即,将RecyclerView,appcompat以及其他任何内容更新到v23,而保留Design Support v22.2.1会产生与上述相同的问题)。因此,新外观CustomDashboardLayout和RecyclerView消失了,希望它也不能按预期运行:
我设法在v23上解决了这个问题,并找到了v22.2.1的解决方法。版本之间的行为完全不同的事实使我相信“按预期工作”不是全部事实。
v23修复:ViewPager上方的CustomDashboardLayout导致了此问题,当它没有被强制强制设为visible =“ gone”时,根本没有将ViewPager添加到层次结构中。随着它的消失,将添加ViewPager,并且RecyclerView可以正确调整其高度。
v22.2.1解决方法:v23修复程序对v22.2.1没有影响,解决方法是在RecyclerView上设置layout_marginBottom =“?attr / actionBarSize”。
很高兴那已经结束了。