在Scroll上从一个视图更改为另一个视图 [英] Changing from one view to another view onScroll

查看:57
本文介绍了在Scroll上从一个视图更改为另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个项目.我有一个布局,在view的顶部是view,在底部的是Scrollview.最初,布局将如下所示.

I am working a project. I have a a layout with a view at top and a Scrollview at the bottom of the view. Initially the layout will look like this.

向上滚动底部布局后.视图应平滑地更改下面的view.而且,如果我向下滚动,视图应该回到其先前的布局.

After I scroll up the bottom layout. The view should smoothly change the the below view. And if I scroll down the view should come back to its previous layout.

如您所见,textviews的位置和大小有所变化.我该如何实现?

As you can see there is a change in the position and size of the textviews. How can I achieve this ?

这是布局:

<?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>

推荐答案

如João所述,使用折叠工具栏,您的代码应像这样 并从此处

Using a Collapse Tool Bar as João said, your code should be like this and getting my answer as base from here

<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" />

<Your Content>上是您应该放置字符串的地方. 抱歉,我无能为力了.您的科迪有点凌乱,真的很难理解.

On <Your Content> is the place where you should put your string. Sorry that I can't help more. Your Cody is a little messy and really hard to understand.

也许,如果您进行编辑,则仅保留重要的代码会有所帮助.

Maybe if you edit leaving only the important codes will help.

但是库可以为您提供帮助.

But maybe this library can help you.

这篇关于在Scroll上从一个视图更改为另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆