如何使用锚点从协调器布局移动视图?

时间:2017-03-17 06:34:09

标签: android android-animation android-coordinatorlayout

假设我的布局类似于:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/bottomIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:src="@drawable/some_image"
        app:layout_anchor="@+id/bottomNavigation"
        app:layout_anchorGravity="top|center"/>

    <some.widget.SomeView
        android:id="@+id/bottomView"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_gravity="bottom"/>
</android.support.design.widget.CoordinatorLayout>

一切都很好,bottomIcon位于bottomView之上。当我尝试翻译bottomView时,所有内容仍然很好,bottomIcon也被翻译了。

然而,当我尝试将bottomView翻译出屏幕时:

public void slideOut(View view) {
    view.animate()
        .translationY(500) //example constant
        .start();
}

//then somewhere call
slideOut(bottomView)

bottomView移出屏幕后跟bottomIcon,直到达到CoordinatorLayout的下限。然后bottomIcon不会向下移动。

即使锚点离开屏幕,我如何实现锚定视图(bottomIcon)跟随其锚点('bottomView')? (解决方案越简单越优越好)

0 个答案:

没有答案