【发布时间】:2018-02-13 19:40:15
【问题描述】:
我目前正在尝试实现某个动画: 我有一个视图(LinearLayout),它应该在按下 fab 按钮时隐藏/显示,并且该视图(LinearLayout)下方的视图(RecyclerView)应该拉长或缩短,以便再次适合屏幕。 LinearLayout 被向上推,因此下面的 RecyclerView 应该以完美的方式拉长,看起来它们会粘在一起。
目前我有如下自定义动画:
slide_down.xml
<translate
android:duration="1000"
android:fromYDelta="-100%"
android:toYDelta="0" />
slide_up.xml
<translate
android:duration="1000"
android:fromYDelta="0"
android:toYDelta="-100%"/>
布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="app.chrono.worker.TabbedActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginBottom="?attr/actionBarSize">
<!-- THIS ONE IS THE LINEAR LAYOUT I WAS TALKING ABOUT -->
<LinearLayout
android:id="@+id/ll_search_whole"
android:layout_width="match_parent"
android:layout_height="@dimen/search_grid"
android:animateLayoutChanges="true"
android:background="@color/colorPrimary"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/ll_search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="2dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="2dp"
android:weightSum="2">
<!-- took out some code here -->
</LinearLayout>
</LinearLayout>
<!-- THIS IS THE RECYCLERVIEW -->
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_below="@id/ll_search_whole"
>
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
不过,RecyclerView 表现迟缓,根本不坚持 LinearLayout。
如何实现我想要的动画?
【问题讨论】:
-
请与 LinearLayout 及其相邻的 RecyclerView 共享布局
-
我添加了,请检查:)
标签: android xml android-layout android-animation