【问题标题】:How to do the new PlayStore parallax effectPlayStore新视差效果怎么做
【发布时间】:2014-10-17 03:12:59
【问题描述】:

有谁知道我怎样才能实现新的视差滚动效果 - 当您在 PlayStore 上打开应用并尝试向下滚动时,您可以看到效果,内容会超出顶部图像。我怎样才能做到这一点?

【问题讨论】:

标签: android android-layout android-animation material-design android-scroll


【解决方案1】:

Google 最近宣布了Design support library,并因此支持实现折叠工具栏

除了固定视图之外,您还可以使用 app:layout_collapseMode="parallax"(以及可选的 app:layout_collapseParallaxMultiplier="0.7" 设置视差 乘数)来实现视差滚动(比如兄弟 ImageView 内CollapsingToolbarLayout)

例子:

<android.support.design.widget.AppBarLayout
        android:layout_height="192dp"
        android:layout_width="match_parent">
    <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
        <android.support.v7.widget.Toolbar
                android:layout_height="?attr/actionBarSize"
                android:layout_width="match_parent"
                app:layout_collapseMode="pin"/>
        </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

【讨论】:

【解决方案2】:

你可以试试这个(FadingActionBar 库): https://github.com/ManuelPeinado/FadingActionBar

在 android 上尝试这个库的示例:https://play.google.com/store/apps/details?id=com.manuelpeinado.fadingactionbar.demo

编辑:而不是第三方库使用这个 AppBarLayout 和 CollapsingToolbarLayout http://android-developers.blogspot.in/2015/05/android-design-support-library.html

【讨论】:

    【解决方案3】:

    【讨论】:

    • 谷歌已经宣布Design support library,为什么还要推荐第三方库!
    • @PareshMayani 谢谢你的信息..但是为什么只为我投反对票呢?所有答案都提供给第三方库,包括接受的答案..
    • Material design library不支持fling手势。滚动视图的糟糕体验!我会试试这个库。
    • 有必要我们只使用官方方法。如果比官方更好,我们可以去第三方..for ex Networking library Retrofit 比官方库更快。那我们的选择是什么?
    • 当然是一个赞成票,因为将 official design support library 添加到 gradle 依赖项的成本肯定等于添加 3rd 方 gradle 依赖项的成本,有时还会带来更大的好处@wisemann 提到的支持
    【解决方案4】:

    实际上,在发布这个问题几分钟后,我遇到了两个库,它们可以实现我正在寻找的效果,甚至更多。

    这里是它们的链接:

    【讨论】:

      【解决方案5】:

      有一个名为FadingActionBar 的库可以完全满足您的要求。您可以在GitHub (click) 上找到库,在Play Store (click) 上找到演示应用程序。

      用法是这样的:

      FadingActionBarHelper helper = new FadingActionBarHelper()
          // Set the ActionBar drawable - basically the color
          .actionBarBackground(R.drawable.ab_background)
          // Set the Header - usually an image
          .headerLayout(R.layout.header)
          // Set the main layout
          .contentLayout(R.layout.activity_scrollview);
      setContentView(helper.createView(this));
      helper.initActionBar(this);
      

      【讨论】:

        【解决方案6】:

        您可以通过跟踪 Recycler View Scrolling 来自定义视差动画

        首先在图像视图布局中。设置父布局小于图像视图,以防止设置translation时图像超出边界Y

        <android.support.percent.PercentRelativeLayout
                android:id="@+id/index_level6_image_section"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:clipChildren="false">
        
                <ImageView
                    android:id="@+id/index_level6_parallaxImage"
                    android:layout_width="match_parent"
                    android:layout_height="240dp"
                    android:layout_centerInParent="true"
                    android:background="@color/timberwolf"
                    android:layout_marginTop="-20"
                    android:layout_marginBottom="-20"
                    android:scaleType="centerCrop"
                    app:imageUrl="@{level6CellViewModel.level6ImageUrl}" />
        
            </android.support.percent.PercentRelativeLayout>
        

        之后,跟踪recycler view 的滚动效果和transitionY image view。

        *** 我正在使用 rxbinding 和 kotlin 来实现。您可以使用相同的想法使用传统的监听方法和java方法。

        RxRecyclerView.scrollEvents(recyclerView)
                            .subscribe { event ->
                                // get the visible cell items of the recycler view
                                val firstVisible = layoutManager.findFirstVisibleItemPosition()
                                val visibleCount = Math.abs(firstVisible - layoutManager.findLastVisibleItemPosition())
        
                                /** loop the visible cell items from the recycler view */
                                for (i in firstVisible..firstVisible + visibleCount) {
                                    event.view().layoutManager?.findViewByPosition(i)?.let { cellItem ->
                                        /** only for index cell level 6 parallax image */
                                        cellItem.findViewById(R.id.index_level6_parallaxImage)?.let { imageView ->
                                            /** setting the parallax effect */
                                            val translationY = (cellItem.top - cellItem.height) / level6ParallaxRate
                                            imageView.translationY = -translationY
                                        }
                                    }
                                }
                            }
        

        【讨论】:

          猜你喜欢
          • 2012-07-09
          • 1970-01-01
          • 1970-01-01
          • 2014-02-05
          • 2021-04-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-11-12
          相关资源
          最近更新 更多