Android - ActivityOptionsCompat - 自定义展开动画

标签 android animation android-appcompat

我目前正在尝试弄清楚如何制作自定义展开动画,使用 ActivityOptionsCompat 似乎是最好的方法;但是,我不太确定如何编写自定义过渡动画来实现我想要的效果。

我在“打开”列表顶部有一个按钮,按下该按钮会将其下方的 ListView 向下移动,展开并显示带有选项的屏幕。我希望这张图片能解释我想要完成的事情。

Expand Transition Animation

我想做的是:

  • 将顶部“打开”栏设置为第二屏幕“标题”中的顶部栏 称为“过滤器”
  • 将“打开”栏正下方的 0 像素高度 View 设置为 名为“FRAME”的扩展选项列表
  • 将 ViewPager 设置为展开选项下方的 0px 高度 View 称为“列表”

但 List 并没有被推开,新屏幕只是覆盖在它上面。

ViewCompat.setTransitionName( filters, "FILTERS" );
ViewCompat.setTransitionName( frame, "FRAME" );
ViewCompat.setTransitionName( viewPager, "LIST" );

ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
            getActivity(), new Pair<>( filters, "FILTERS" ), new Pair<>( frame, "FRAME" ), new Pair<>( (View)viewPager, "LIST" ) );


ActivityCompat.startActivity( getActivity(), new Intent( getActivity(), Filters.class ),
            options.toBundle() );

有谁知道如何实现这种风格的过渡动画?

感谢您的宝贵时间和帮助。

最佳答案

如果不必是另一项 Activity ,您可以使用此 nice library here我过去也用过 umano。

enter image description here

要使用它,您需要将它包含在您的 gradle 依赖项中:

compile 'com.sothree.slidinguppanel:library:3.2.0'

然后你可以像这样使用它:

<com.sothree.slidinguppanel.SlidingUpPanelLayout
    xmlns:sothree="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    sothree:umanoPanelHeight="68dp"
    sothree:umanoShadowHeight="4dp"
    sothree:umanoParallaxOffset="100dp"
    sothree:umanoDragView="@+id/dragView"
    sothree:umanoOverlay="true"
    sothree:umanoScrollableView="@+id/list">

    <!-- MAIN CONTENT -->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <android.support.v7.widget.Toolbar
            xmlns:sothree="http://schemas.android.com/apk/res-auto"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/main_toolbar"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            sothree:theme="@style/ActionBar"
            android:layout_width="match_parent"/>
        <TextView
            android:id="@+id/main"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="?attr/actionBarSize"
            android:gravity="center"
            android:text="Main Content"
            android:clickable="true"
            android:focusable="false"
            android:focusableInTouchMode="true"
            android:textSize="16sp" />
    </FrameLayout>

    <!-- SLIDING LAYOUT -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        android:orientation="vertical"
        android:clickable="true"
        android:focusable="false"
        android:id="@+id/dragView">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="68dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/name"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:textSize="14sp"
                android:gravity="center_vertical"
                android:paddingLeft="10dp"/>

            <Button
                android:id="@+id/follow"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:textSize="14sp"
                android:gravity="center_vertical|right"
                android:paddingRight="10dp"
                android:paddingLeft="10dp"/>

        </LinearLayout>

        <ListView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">
        </ListView>
    </LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

关于Android - ActivityOptionsCompat - 自定义展开动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33881760/

相关文章:

android - Xtify 注册如何运作?

java - Android 中使用自定义 View 的加载动画

android - proguard - AppCompat 不支持 proguard/minify 后的当前主题功能

android - 使用 BottomAppBar Material 设计组件的 fragment 过渡

android - 是否可以在显示键盘时处理 Firefox 移动版中的 jQuery 输入事件?

Android沿路径移动对象

java - 使用 2 个 Java 类显示 1 个 XML 文件的信息

android - 更新到支持库 26.0.0 时,找不到与给定名称 : attr 'android:keyboardNavigationCluster' . 匹配的资源

android - 我如何让 mixlr 广播流在 Android 应用程序中播放?

r - 如何创建地理空间/时间数据的动画