【发布时间】:2017-11-22 10:22:04
【问题描述】:
我使用ConstraintLayout 作为我的视图。在其中我放置了一个ViewPager,适配器包含的视图之一是RecyclerView。
当我尝试仅放置图像时,我无法再滚动的高度缺失。该高度看起来与我在顶部使用的空间相同 (Toolbar + TabLayout)。
当使用RelativeLayout 而不是ConstraintLayout 时,它可以工作
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/homeToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/toolbarColor">
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:padding="7dp"
android:src="@drawable/ic_menu"
tools:ignore="RtlHardcoded" />
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="horizontal"
tools:ignore="RtlHardcoded">
<android.support.v7.widget.AppCompatImageView
style="@style/RippleEffect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:padding="7dp" />
<android.support.v7.widget.AppCompatImageView
style="@style/RippleEffect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:padding="7dp"
android:src="@drawable/ic_search" />
</LinearLayout>
</RelativeLayout>
<android.support.design.widget.TabLayout
android:id="@+id/homeTabLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/toolbarColor"
app:layout_constraintTop_toBottomOf="@+id/homeToolbar"
app:tabMode="scrollable" />
<android.support.v4.view.ViewPager
android:id="@+id/homeViewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/homeTabLayout"
/>
</android.support.constraint.ConstraintLayout>
这就是我所看到的(见最后一个达斯维德)
【问题讨论】:
-
我也遇到过类似的情况,确实是工具栏的原因。我使工具栏可滚动,它就这样固定了。您可以使您的工具栏可滚动或在 viewpager 中使用 paddingBottom
-
使用
paddingBottom不是解决方案,因为我不想计算视图的缺失底部。这将是一个快速的解决方法,但不是解决方案,您不同意吗? -
刚刚得到答案@Lukingan。我刚刚发布了解决方案
标签: android android-recyclerview android-viewpager android-constraintlayout