Android - 将内容滚动到屏幕顶部

时间:2016-01-28 12:03:01

标签: android scroll

我的XML中有一个带有下图(1)图像结构的应用程序。我需要你做滚动,应用程序仍然如图像(2)。我不知道它是如何工作的CoordinatorLayout,NestedScrollView ......

我的xml需要进行哪些更改才能获得它?谢谢

enter image description here

XML

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/color_primary_dark">

    <include
        android:id="@+id/fondo_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/toolbar" />

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="@color/black">

            <com.example.HackyViewPager
                android:id="@+id/home_pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/grey_dark"/>

            <com.viewpagerindicator.CirclePageIndicator
                android:id="@+id/home_indicator"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent"
                android:padding="15dp"/>

        </RelativeLayout>

        <include
            android:id="@+id/home_footer"
            layout="@layout/home_footer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/sliding_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/color_primary_dark"
            android:elevation="0dp"
            app:tabMode="scrollable"
            app:tabGravity="center"/>

        <android.support.v4.view.ViewPager
            android:id="@+id/tabpager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/grey_dark" />

    </LinearLayout>

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

如下所示,您将得到一个粗略的想法: -

div#flex { width: 100%; height: auto; margin: 0px; max-width: initial; }

这只是一个粗略的想法,您可以根据您的设计进行调整,但不要复制粘贴此代码,因为它不起作用。正如我已经给出了这个代码,简要介绍了如何使用nestedScrollView和coordinatorLayout。 要获得更多理解,您可以查看Material Design教程