android - ViewPager 被切断

标签 android android-recyclerview android-tablayout swiperefreshlayout

我有一个 TabLayout,在一个包含 ViewPager 的 SwipeRefreshLayout 下方(每个页面都有一个 RecyclerView)。我以前在每个页面 fragment 中都有 SRL,但现在更改了它,所以我只有一个更方便的 fragment 。 由于某种原因,ViewPager 被切断,我无法一直滚动到 RecyclerView 的顶部。

有人对此有解决方案吗?

enter image description here

这是我的布局 xml: activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<android.support.design.widget.TabLayout
    android:id="@+id/mainTabLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:elevation="6dp"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:tabGravity="fill" />

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/mainSwipeContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.view.ViewPager
        android:id="@+id/mainViewPager"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/mainTabLayout" />

</android.support.v4.widget.SwipeRefreshLayout>

</RelativeLayout>

fragment 布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/mainRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true" />

</RelativeLayout>

最佳答案

在您的 activity_main 中用 LinearLayout 替换您的 RelativeLayout。

关于android - ViewPager 被切断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35663870/

相关文章:

android - TabLayout 选项卡文本在 viewPager.setCurrentItem() 之后未突出显示

android - 在具有相对布局父级的 fragment 中使用持久性 Bottom Sheet

android - 来自 AWS Android SDK 示例应用程序的 DynamoDB 表不在控制台中

android - 更改java中动态UI的进度条样式

android - 如何在回收站 View 中隐藏特定行的 View ?

android - 在两个 fragment 之间添加一个监听器

android - Alert Dialog.builder object.create() vs object.show() vs obj.create().show() 之间的区别

android - 两个 View 之间的自定义画线无法正常工作

android - 在 Recylerview 中实现复选框。 MVVM Room ViewModel LiveData Recylerview 复选框

android - 来自可绘制资源 ID #0x7f0601d8 的异常 android.content.res.Resources$NotFoundException : File res/color/selector_tab_blue_white. xml