我試圖在一些DP滾動後將視圖設置爲動畫並將其隱藏,並且我將所有內容都設置爲正常,但問題在於當它彈出時您在應該觸發動畫的Y值之前或之後緩慢滾動。爲視圖平滑隱藏/顯示動畫並填充空白空間
我認爲輕彈是因爲我有它的可見性設置爲過去了,更新其他視圖match_parent,它不會只用TraslationY工作:
view.animate()
.translationY(-view.getBottom())
.alpha(0)
.setDuration(HEADER_HIDE_ANIM_DURATION)
.setInterpolator(new DecelerateInterpolator());
我試圖設置佈局相對和View 2作爲match_parent來看看我是否能避免可見性改變,但它沒有工作...
我已經實現了從谷歌I/O 2014 BaseActivity.java文件所需的所有代碼: https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/BaseActivity.java#L17
而動畫的作品......但我認爲,因爲我的customview不是具有疊加屬性的動作條,所以customview不會離開,下面的LinearLayout將不會填充空白空間(沒有)。
因此,我使它與animationlistener一起工作,並在動畫結束時設置自定義視圖的可見性消失,但當您接近預期的觸發動畫的Y點時,它會以可怕的方式輕彈(輕彈爲自定義視圖可視性消失了,下面的LinearLayout需要調整自己的大小以填充空白區域,並且如果您在那裏緩慢滾動,則會很快重複)。
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:animateLayoutChanges="true">
<com.project.app.layouts.TabsLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tabs">
<FrameLayout
android:id="@+id/content_frame_header"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white"/>
</LinearLayout>
</RelativeLayout>
有沒有辦法做到這一點時,它不是一個動作條?
編輯: 添加關於如何緩慢滾動Y點觸發動畫以隱藏/顯示時它將如何彈出的註釋。
我建議您在一張紙上繪製您想要的動畫步驟,並將其作爲圖像張貼在這裏,或者您可以使用一些繪圖程序。通過這種方式,我們將展現您所期待的最終效果。 – vovahost 2014-11-03 23:31:58
很簡單,只需要一個視圖1消失並查看2填充視圖1左側的空白區域。就像當您在Google I/O 2014中向下滾動操作欄時隱藏操作欄,但使用自定義視圖而不是操作欄時。 – Motheus 2014-11-04 00:53:51
也許這很容易實現,但很難理解視圖1和視圖2如何在佈局中定位。你提到將可見性設置消失,但我們沒有看到任何代碼。如果你想得到一個很好的答案,那麼請添加一些代碼,也許草圖。 – vovahost 2014-11-04 08:24:45