我目前正试图弄清楚如何制作自定义扩展动画,并且使用ActivityOptionsCompat似乎是最好的方法;但是,我不确定如何编写自定义过渡动画来实现我想要的效果。
我在列表顶部有一个按钮'打开'按下后会将ListView下方的ListView移动,展开并显示带有选项的屏幕。我希望这张图片能够解释我想要完成的任务。
我想做的是:
但是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() );
有谁知道如何完成这种过渡动画风格?
感谢您的时间和帮助。
答案 0 :(得分:3)
如果它不必是另一项活动,您可以使用我过去使用的umano nice library 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>
答案 1 :(得分:0)
ActivityOptionsCompat.makeSceneTransitionAnimation()
仅在API 21+设备上有效。
要查看动画,需要在样式级别启用过渡
<!-- enable window content transitions -->
<item name="android:windowContentTransitions">true</item>
并且需要为调用和调用目标布局的视图设置相同的TransitionName。
无论如何,过渡将像放大/缩小,而不是滚动。