【问题标题】:Android ViewPager inside a NestedScrollViewNestedScrollView 中的 Android ViewPager
【发布时间】:2018-05-14 21:17:44
【问题描述】:

我需要显示一些文本,并且在底部我需要两个选项卡。当前代码仅在文本很小的情况下才有效,如果文本填满整个屏幕,则滚动时不会显示选项卡。 我的活动 XML 是:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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:fillViewport="true"
    tools:context="dk.zispa.vibetasks.TaskDetailedView">

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

        <RelativeLayout
            android:id="@+id/task_view_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/taskTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="5dp"
                android:layout_marginTop="10dp"
                android:clickable="true"
                android:focusable="true"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/black"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/taskBreadcrumbs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/taskTitle"
                android:layout_marginStart="5dp"
                android:layout_marginTop="3dp"
                android:clickable="true"
                android:focusable="true"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/secondaryText"
                android:textSize="14sp" />

            <View
                android:id="@+id/divider"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@id/taskBreadcrumbs"
                android:layout_marginBottom="10dp"
                android:layout_marginTop="10dp"
                android:background="@color/divider" />

            <TextView
                android:id="@+id/taskDescription"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/divider"
                android:layout_marginStart="5dp"
                android:clickable="false"
                android:focusable="false"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/secondaryText" />

            <LinearLayout
                android:id="@+id/hoursInfo"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/taskDescription"
                android:layout_margin="5dp"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/taskEstimatedHours"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@color/orange"
                    android:gravity="center"
                    android:paddingBottom="3dp"
                    android:paddingTop="3dp"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="@color/white" />

                <TextView
                    android:id="@+id/taskWorkedHours"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@color/colorPrimaryLight"
                    android:gravity="center"
                    android:paddingBottom="3dp"
                    android:paddingTop="3dp"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="@color/white" />

            </LinearLayout>

        </RelativeLayout>


        <android.support.v4.view.ViewPager
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/hoursInfo">

            <android.support.design.widget.TabLayout
                android:id="@+id/book_tab_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tabGravity="fill">

                <android.support.design.widget.TabItem
                    android:id="@+id/book_description_tab_item"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="TAB1" />

                <android.support.design.widget.TabItem
                    android:id="@+id/book_reviews_tab_item"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="TAB2" />

            </android.support.design.widget.TabLayout>
        </android.support.v4.view.ViewPager>
    </LinearLayout>


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

您知道如何在向下滚动时使标签可见吗? 提前谢谢你

【问题讨论】:

    标签: android xml android-viewpager android-nestedscrollview


    【解决方案1】:

    您可以尝试将 LinearLayout 替换为 RelativeLayout。将 task_view_layout 设置为 alignParentTop="true",将视图分页器设置为 alignParentBottom="true" 和 layoutBelow="@+id/task_view_layout"

    【讨论】:

    • 这没有帮助,如果你必须滚动仍然看不到标签。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-28
    • 2020-01-09
    • 1970-01-01
    • 2021-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多