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

你好!

我希望这个视图可以滚动:

《android – 在使用TabLayout和ViewPager的Fragment中启用滚动》

如您所见,TAB1中的“TEMP CONTENT”就是模拟可能出现的临时内容.

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

这是持有视图的布局:

<?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的片段布局:

<!-- 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>

提前致谢!

最佳答案 一起使用Scrollview和NestedScrollview.

这是一个例子Code

>在View分页器片段中使用NestedScrollview.
>对于您的活动布局,将Scrollview添加为根标签并添加android:fillViewport =“true”

点赞