Android 在Croll上从一个视图更改为另一个视图
我在做一个项目。我有一个布局,顶部有一个Android 在Croll上从一个视图更改为另一个视图,android,android-layout,Android,Android Layout,我在做一个项目。我有一个布局,顶部有一个视图,底部有一个滚动视图。最初的布局是这样的 之后我向上滚动底部布局。该视图应平滑地更改下面的视图。如果我向下滚动,视图将返回到以前的布局 如您所见,文本视图的位置和大小发生了变化。我怎样才能做到这一点 布局如下: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://s
视图
,底部有一个滚动视图
。最初的布局是这样的
之后我向上滚动底部布局。该视图应平滑地更改下面的视图
。如果我向下滚动,视图将返回到以前的布局
如您所见,文本视图的位置和大小发生了变化。我怎样才能做到这一点
布局如下:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/home_parentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="@color/AT_charcoal">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="9dp"
android:background="@drawable/topographybackgroundx">
<RelativeLayout
android:id="@+id/layout_header_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp">
<RelativeLayout
android:id="@+id/top_ExpandedHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/image_invisalignLogo"
android:layout_width="108dp"
android:layout_height="26dp"
android:background="@drawable/invis_logo"
android:contentDescription="@null" />
<ImageButton
android:id="@+id/image_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@drawable/ic_profile_wht"
android:contentDescription="@null" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/number_RelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/layout_aligner_expanded_change"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<TextView
android:id="@+id/image_alignerNumber"
style="@style/BigNumber"
android:layout_width="wrap_content"
android:layout_height="138dp"
android:layout_alignParentStart="true"
android:layout_below="@+id/textview_alignerTimeChange"
android:maxLength="2"
android:maxLines="1"
android:text="@string/three"
android:textSize="124sp" />
<TextView
android:id="@+id/textview_alignerChange"
style="@style/BodyWhite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="80dp"
android:layout_toEndOf="@id/image_alignerNumber"
android:letterSpacing="0.03"
android:text="@string/days_alignerchange" />
<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/image_selfie_icon"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
app:civ_border_color="#FFFFFFFF"
app:civ_border_width="2dp" />
<TextView
android:id="@+id/textview_6alignerNumber"
style="@style/HeaderWhite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/image_alignerNumber"
android:layout_below="@id/image_alignerNumber"
android:layout_marginTop="2dp"
android:letterSpacing="0.03"
android:text="@string/aligner_number" />
<TextView
android:id="@+id/textview_expanalignerNumber"
style="@style/HeaderWhite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/image_alignerNumber"
android:layout_toEndOf="@id/textview_6alignerNumber"
android:text="5" />
<TextView
android:id="@+id/textview_alignerTimeChange"
style="@style/LargeHeaderWhite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="17dp"
android:letterSpacing="0.03"
android:text="@string/aligner_change"
android:visibility="gone" />
<Button
android:id="@+id/button_change"
style="@style/TextButtonWhite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textview_alignerTimeChange"
android:layout_marginTop="15dp"
android:background="@color/AT_lushGreen"
android:gravity="center_vertical"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="@string/changenow"
android:visibility="gone" />
</RelativeLayout>
<View
android:id="@+id/dividerline"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_below="@id/number_RelativeLayout"
android:layout_marginTop="12dp"
android:background="@color/AT_line" />
<TextView
android:id="@+id/addPhoto_TextView"
style="@style/BtnTextBlue18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/dividerline"
android:layout_marginTop="10dp"
android:text="@string/add_photo" />
<TextView
android:id="@+id/goCalendar_TextView"
style="@style/BtnTextGold18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="@id/dividerline"
android:layout_marginTop="7dp"
android:text="@string/go_calendar" />
</RelativeLayout>
</RelativeLayout>
<include
layout="@layout/homescreen_scrollview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/layout_header_profile"
android:layout_marginTop="15dp" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
您可以使用
及
编辑:一些代码
<android.support.design.widget.CoordinatorLayout
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.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary">
<ImageView
android:id="@+id/expandedImage"
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="@drawable/beach_scene"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7"
/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" >
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/sample_string"/>
</android.support.v4.widget.NestedScrollView>
使用折叠工具栏,正如João所说,您的代码应该是这样的
我的答案是根据
库可以帮助您。发布您的XML
代码。我认为这主要是通过java完成的。在我的布局中,父视图是一个RelativeLayout
,由另一个RelativeLayout
作为上视图组成,然后在第一个视图的底部有一个滚动视图@Heisen Bergins没有说,显示你的代码。添加了布局@Heisen BergI我没有使用工具栏。在我的布局中,父视图是一个RelativeLayout
,由另一个RelativeLayout
作为上视图组成,然后在第一个视图的底部有一个滚动视图。添加了布局。再次检查您需要更改xml布局才能获得此效果。但是,如果没有工具栏
我该如何使用您的解决方案,让我试试。我只是不知道这种转变是否会在这方面起作用。我需要将一个文本视图从一个特定位置移动到另一个特定位置。你可以在截图中看到。是的,这就是为什么我放了图书馆,应该有帮助。在没有库的情况下,你可以尝试在工具栏中放置你想要的布局,使其最终不可见,并在崩溃时再次可见。
<android.support.design.widget.CoordinatorLayout
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:clipToPadding="false">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="210dp"
android:background="@color/WHITE">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:collapsedTitleTextAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
app:expandedTitleMarginStart="72dp"
app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<Your Content>
<android.support.v7.widget.Toolbar
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="40dp"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include
layout="@layout/homescreen_scrollview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/layout_header_profile"
android:layout_marginTop="15dp" />