【问题标题】:The fragment getting cut by view pagger layout片段被视图分页器布局切割
【发布时间】:2018-12-15 15:34:56
【问题描述】:

首先,我想制作一个 tablayout 片段,在片段 One 中我想添加 recycler view ,但是 recyclerview 的顶部被视图分页器或顶部的标签布局切割。

getting cut at the top

recyclerview 的顶部被视图分页器剪切。工具栏在其他xml中分开

这是fragmentOne.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.example.yehezkiel.eclassapp.OneFragment">

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

        <include
            layout="@layout/navbar_action"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"></include>

        <ProgressBar
            android:id="@+id/progressBar2"
            style="?android:attr/progressBarStyle"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_horizontal"
            android:visibility="visible"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="304dp" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/MainRView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="2dp"
            android:layout_marginEnd="6dp"
            android:layout_marginStart="6dp"
            android:layout_marginTop="2dp"
            android:clipToPadding="false"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="@layout/activity_tablayout"
            app:layout_constraintTop_toTopOf="@layout/activity_tablayout">


        </android.support.v7.widget.RecyclerView>

    </LinearLayout>


</FrameLayout>

这是activity_tablayout.xml

<?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"
    tools:context="com.example.yehezkiel.eclassapp.tablayoutActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar3"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:tabGravity="fill"
            app:tabMode="fixed" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"  />


</android.support.constraint.ConstraintLayout>

我已经尝试过下面的代码,或者改变方向。但是还是出错了,求大神帮忙

【问题讨论】:

  • 在您的activity_tablayout.xml 中而不是ConstraintLayout 中,只需使用垂直方向的LinearLayout
  • 感谢 heisenbrg 你救了我

标签: android xml android-layout android-fragments fragment


【解决方案1】:

这是因为您将 CoordinatorLayout 与 ListView 一起使用。您可以将您的实现更改为 RecyclerView 以实现正确的滚动。

或者如果你是5.0以上的,你可以使用下面这段代码

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
 listView.setNestedScrollingEnabled(true);} 

我认为 CoordinatorLayout 仅适用于 NestedScrollingChild 的子级。

【讨论】:

  • 你离解决方案太远了。顺便说一句,不错的尝试!
【解决方案2】:

尝试用你的activity_tablayout.xml中的CoordinatorLayout替换ContraintLayout

Check this out为源代码,附示例。

也可以看看这个视频

https://www.youtube.com/watch?v=DyyNxJtYTBc

希望这会有所帮助。

【讨论】:

    【解决方案3】:

    您将 CoordinatorLayout 转换为 LinearLayout 并将方向设置为“垂直”,如下所示。我认为这将解决您的问题。

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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"
        android:orientation="vertical"
        tools:context="com.example.yehezkiel.eclassapp.tablayoutActivity">
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar3"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:tabGravity="fill"
                app:tabMode="fixed" />
        </android.support.design.widget.AppBarLayout>
        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-13
      • 1970-01-01
      • 2018-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多