繁体   English   中英

NestedScrollView中的Android ViewPager

[英]Android ViewPager inside a NestedScrollView

我需要显示一些文本,在底部,我需要两个选项卡。 当前代码仅在文本较小时有效,如果文本填满整个屏幕,则滚动时不会显示选项卡。 在此处输入图片说明 在此处输入图片说明 我的活动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>

您有什么想法,当您向下滚动时如何显示选项卡? 先感谢您

您可以尝试用RelativeLayout替换LinearLayout。 将task_view_layout和alignParentTop =“ true”放在一起,视图分页器将alignParentBottom =“ true”和layoutBelow =“ @ + id / task_view_layout”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM