假设我的布局类似于:
<?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')? (解决方案越简单越优越好)