android - 在使用 TabLayout 和 ViewPager 的 Fragment 中启用滚动

标签 android android-fragments android-viewpager android-tablayout

您好! 我希望此 View 可滚动:

enter image description here

如您所见,TAB1 中的“TEMP CONTENT”只是用来模拟可能出现的临时内容。

我现在要做的是让整个页面都可以滚动。我设法做的是使 TAB1 的内容,因此,TabLayout 的内容,可滚动,但这不是我想要做的。如上所述,整个页面应该是。

这是持有 View 的布局:

<?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"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="at.codecrane.whosnext.MainActivity">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="200dp">

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:srcCompat="@android:color/darker_gray" />

            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="100dp"
                android:layout_height="100dp"
                app:srcCompat="@drawable/ic_face"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="32dp" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/imageView3"
                android:layout_centerHorizontal="true"
                android:text="Temp Name"
                android:textSize="18sp" />
        </RelativeLayout>



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

            <android.support.design.widget.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tabIndicatorColor="@color/colorPrimary">

                <android.support.design.widget.TabItem
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="General" />

                <android.support.design.widget.TabItem
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Statistics" />

            </android.support.design.widget.TabLayout>

        </android.support.v4.view.ViewPager>
    </LinearLayout>

这是 ViewPager-Content 的 fragment 布局:

<!-- TODO: Update blank fragment layout -->
<LinearLayout 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"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TEMP CONTET"
        android:textSize="20dp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TEMP CONTET"
        android:textSize="20dp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TEMP CONTET"
        android:textSize="20dp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TEMP CONTET"
        android:textSize="20dp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TEMP CONTET"
        android:textSize="20dp" />
</LinearLayout>

提前致谢!

最佳答案

同时使用 ScrollviewNestedScrollview

这是一个例子Code

  1. 在您的 View 分页器 fragment 中使用 NestedScrollview

  2. 对于您的 Activity 布局,添加 Scrollview 作为根标记并添加 android:fillViewport="true"

关于android - 在使用 TabLayout 和 ViewPager 的 Fragment 中启用滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43054849/

相关文章:

android - 我可以使用openCV4Android处理Android相机录制的视频吗?

c# - Android 的单声道,WebView 输入字段文件选择器不起作用

android - 在 Fragment 中获取工具栏

android - Viewpager 没有得到最后一项

android - 像android market一样使用ViewPager进行水平 View 滑动

android - 推送通知 iOS 和 Android 客户端到客户端 native 代码

android - 如何处理android通知警报中的多个intent Action

java - 停止 fragment 的函数和调用并重置内部变量

android - oncreate option menu of fragment stoppng activity oncreateoptionmenu

tabs - 在 Espresso 测试时选择 native 标签