Android-将内容滚动到屏幕顶部
我有一个应用程序,在我的XML中具有下面(1)的图像结构。我需要你做滚动,应用程序仍然如图(2)所示。我不知道它是如何协调布局的,NestedScrollView 我需要在xml中做哪些更改才能获得它?多谢各位 XMLAndroid-将内容滚动到屏幕顶部,android,scroll,Android,Scroll,我有一个应用程序,在我的XML中具有下面(1)的图像结构。我需要你做滚动,应用程序仍然如图(2)所示。我不知道它是如何协调布局的,NestedScrollView 我需要在xml中做哪些更改才能获得它?多谢各位 XML <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
<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>
按以下步骤操作,您将大致了解:-
<android.support.design.widget.CoordinatorLayout 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.support.design.widget.AppBarLayout
android:id="@+id/appbarlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<com.example.HackyViewPager
android:id="@+id/home_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_dark"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll">
<!-- put your own design like Relative layout then viewpager etc -->
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
这只是一个粗略的想法,您可以根据自己的设计进行调整,但不要复制粘贴此代码,因为它不起作用。正如我给出这段代码是为了简单介绍如何使用nestedScrollView和coordinatorLayout。
要了解更多信息,您可以查看材料设计教程执行以下操作,您将大致了解:-
<android.support.design.widget.CoordinatorLayout 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.support.design.widget.AppBarLayout
android:id="@+id/appbarlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<com.example.HackyViewPager
android:id="@+id/home_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_dark"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll">
<!-- put your own design like Relative layout then viewpager etc -->
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
这只是一个粗略的想法,您可以根据自己的设计进行调整,但不要复制粘贴此代码,因为它不起作用。正如我给出这段代码是为了简单介绍如何使用nestedScrollView和coordinatorLayout。
要了解更多信息,请查看材料设计教程是否尝试了ScrollView?你到底想滚动什么?我需要在顶部显示RelativeLayout而不消失你试过滚动视图吗?你到底想滚动什么?我需要在顶部显示RelativeLayout而不消失