Android ViewPager里面有一个NestedScrollView

时间:2017-11-30 20:26:23

标签: android xml android-viewpager android-nestedscrollview

我需要显示一些文字,在底部我需要两个标签。当前代码仅在文本较小时才有效,如果文本填满整个屏幕,则滚动时不显示选项卡。 enter image description here enter image description here 我的活动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>

有什么想法,当您向下滚动时,如何让标签可见? 提前谢谢

1 个答案:

答案 0 :(得分:0)

您可以尝试将LinearLayout替换为RelativeLayout。将task_view_layout与alignParentTop =&#34; true&#34;和对齐寻呼机与alignParentBottom =&#34;真&#34;和layoutBelow =&#34; @ + id / task_view_layout&#34;