将 2 个视图一起设置动画会隐藏另一个视图所在的位置
Animating 2 views together hides one where the other view was
我有 2 个视图(一个按钮和一个滑块),一个在另一个上方,我正在为下方的视图设置动画,使其超出框架,我希望另一个视图也以相同的数量进行动画处理。我的问题是下视图曾经是顶视图的地方。 (见图片)。这两个动画都是由视图模型 属性 更改触发的。
TimeView.Animate().TranslationYBy(ViewModel.IsShowingEmployees ? -TimeView.Height : TimeView.Height);
MyPositionButton.Animate().TranslationYBy(ViewModel.IsShowingEmployees ? -TimeView.Height : TimeView.Height);
动画前:
动画后:
如何让下视图停止剪裁上视图?我试图改变视图的 Z 和 TransitionZ 属性以确保按钮高于栏。我还尝试将栏的可见性设置为在动画完成时消失。我还尝试使用 TranslateAnimation 以便我可以控制 Fill 属性。 None 这些东西都奏效了。
看一下 axml。
<RelativeLayout
android:id="@+id/map_area_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/under_list_view">
<RelativeLayout
android:id="@+id/map_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="@+id/time_view"
android:layout_width="300dp"
android:layout_height="44dp"
android:background="#ddffffff"
android:layout_alignParentBottom="true">
<TextView
android:id="@+id/time_text_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:text="4:56PM"
android:textColor="@color/gray_dark"
android:textSize="18dp"
android:gravity="center_vertical"
android:layout_marginLeft="10dp" />
<SeekBar
android:id="@+id/time_seek_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:max="1440"
android:progress="700"
android:progressDrawable="@drawable/custom_scrubber_progress"
android:thumb="@drawable/custom_scrubber_control"
android:secondaryProgress="0"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/time_text_view" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/time_view"
android:layout_alignParentLeft="true"
android:layout_margin="5dp">
<ImageButton
android:id="@+id/my_location_button"
android:layout_height="50dp"
android:layout_width="50dp"
android:background="@drawable/ek_fab_button_ripple_white"
android:src="@drawable/ic_my_location_24p"
android:tint="@color/gray_dark" />
</RelativeLayout>
</RelativeLayout>
打开 "Show layout bounds" 后,OP 发现他正在为 Button
本身设置动画,而不是 RelativeLayout
。设置动画后 RelativeLayout
不会发生剪裁。
旧答案
更改 RelativeLayout
的位置,使带有 ImageButton
的位置声明在另一个带有 SeekBar
的下方。在这种情况下,ImageButton
将绘制在 SeekBar
.
之上
<RelativeLayout
android:id="@+id/map_area_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/under_list_view">
<RelativeLayout
android:id="@+id/map_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="@+id/time_view"
android:layout_width="300dp"
android:layout_height="44dp"
android:background="#ddffffff"
android:layout_alignParentBottom="true">
<TextView
android:id="@+id/time_text_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:text="4:56PM"
android:textColor="@color/gray_dark"
android:textSize="18dp"
android:gravity="center_vertical"
android:layout_marginLeft="10dp" />
<SeekBar
android:id="@+id/time_seek_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:max="1440"
android:progress="700"
android:progressDrawable="@drawable/custom_scrubber_progress"
android:thumb="@drawable/custom_scrubber_control"
android:secondaryProgress="0"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/time_text_view" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/time_view"
android:layout_alignParentLeft="true"
android:layout_margin="5dp">
<ImageButton
android:id="@+id/my_location_button"
android:layout_height="50dp"
android:layout_width="50dp"
android:background="@drawable/ek_fab_button_ripple_white"
android:src="@drawable/ic_my_location_24p"
android:tint="@color/gray_dark" />
</RelativeLayout>
</RelativeLayout>
我有 2 个视图(一个按钮和一个滑块),一个在另一个上方,我正在为下方的视图设置动画,使其超出框架,我希望另一个视图也以相同的数量进行动画处理。我的问题是下视图曾经是顶视图的地方。 (见图片)。这两个动画都是由视图模型 属性 更改触发的。
TimeView.Animate().TranslationYBy(ViewModel.IsShowingEmployees ? -TimeView.Height : TimeView.Height);
MyPositionButton.Animate().TranslationYBy(ViewModel.IsShowingEmployees ? -TimeView.Height : TimeView.Height);
动画前:
动画后:
如何让下视图停止剪裁上视图?我试图改变视图的 Z 和 TransitionZ 属性以确保按钮高于栏。我还尝试将栏的可见性设置为在动画完成时消失。我还尝试使用 TranslateAnimation 以便我可以控制 Fill 属性。 None 这些东西都奏效了。
看一下 axml。
<RelativeLayout
android:id="@+id/map_area_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/under_list_view">
<RelativeLayout
android:id="@+id/map_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="@+id/time_view"
android:layout_width="300dp"
android:layout_height="44dp"
android:background="#ddffffff"
android:layout_alignParentBottom="true">
<TextView
android:id="@+id/time_text_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:text="4:56PM"
android:textColor="@color/gray_dark"
android:textSize="18dp"
android:gravity="center_vertical"
android:layout_marginLeft="10dp" />
<SeekBar
android:id="@+id/time_seek_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:max="1440"
android:progress="700"
android:progressDrawable="@drawable/custom_scrubber_progress"
android:thumb="@drawable/custom_scrubber_control"
android:secondaryProgress="0"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/time_text_view" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/time_view"
android:layout_alignParentLeft="true"
android:layout_margin="5dp">
<ImageButton
android:id="@+id/my_location_button"
android:layout_height="50dp"
android:layout_width="50dp"
android:background="@drawable/ek_fab_button_ripple_white"
android:src="@drawable/ic_my_location_24p"
android:tint="@color/gray_dark" />
</RelativeLayout>
</RelativeLayout>
打开 "Show layout bounds" 后,OP 发现他正在为 Button
本身设置动画,而不是 RelativeLayout
。设置动画后 RelativeLayout
不会发生剪裁。
旧答案
更改 RelativeLayout
的位置,使带有 ImageButton
的位置声明在另一个带有 SeekBar
的下方。在这种情况下,ImageButton
将绘制在 SeekBar
.
<RelativeLayout
android:id="@+id/map_area_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/under_list_view">
<RelativeLayout
android:id="@+id/map_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="@+id/time_view"
android:layout_width="300dp"
android:layout_height="44dp"
android:background="#ddffffff"
android:layout_alignParentBottom="true">
<TextView
android:id="@+id/time_text_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:text="4:56PM"
android:textColor="@color/gray_dark"
android:textSize="18dp"
android:gravity="center_vertical"
android:layout_marginLeft="10dp" />
<SeekBar
android:id="@+id/time_seek_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:max="1440"
android:progress="700"
android:progressDrawable="@drawable/custom_scrubber_progress"
android:thumb="@drawable/custom_scrubber_control"
android:secondaryProgress="0"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/time_text_view" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/time_view"
android:layout_alignParentLeft="true"
android:layout_margin="5dp">
<ImageButton
android:id="@+id/my_location_button"
android:layout_height="50dp"
android:layout_width="50dp"
android:background="@drawable/ek_fab_button_ripple_white"
android:src="@drawable/ic_my_location_24p"
android:tint="@color/gray_dark" />
</RelativeLayout>
</RelativeLayout>