【问题标题】:Animating 2 views together hides one where the other view was将 2 个视图一起设置动画会隐藏另一个视图所在的位置
【发布时间】:2017-03-23 02:36:18
【问题描述】:

我有 2 个视图(一个按钮和一个滑块),一个在另一个之上,我正在为较低的一个超出框架设置动画,并且我希望另一个视图也以相同的数量进行动画处理。我的问题是,下视图曾经是顶视图的位置。 (见图片)。两个动画都是由视图模型属性更改触发的。

TimeView.Animate().TranslationYBy(ViewModel.IsShowingEmployees ? -TimeView.Height : TimeView.Height);
MyPositionButton.Animate().TranslationYBy(ViewModel.IsShowingEmployees ? -TimeView.Height : TimeView.Height);

动画前:

动画后:

如何让下视图停止裁剪上视图?我试图改变视图的 Z 和 TransitionZ 属性以确保按钮高于栏。我还尝试在动画完成时将栏的可见性设置为 Gone。我还尝试使用 TranslateAnimation 以便我可以控制 Fill 属性。这些都没有奏效。

这里是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>

【问题讨论】:

    标签: android animation xamarin.android android-animation


    【解决方案1】:

    打开“显示布局边界”后,OP 发现他正在为Button 本身设置动画,而不是RelativeLayout。在为RelativeLayout 设置动画后,不会发生剪辑。

    旧答案

    更改您的RelativeLayouts 的位置,以便将带有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>
    

    【讨论】:

    • 对不起,我忘了在 OP 中提到这是我尝试过的解决方案之一,它得到了相同的结果。
    • 你能分享一张开启“显示布局边界”模式的截图吗?
    • 那是我需要的轻推。在启用“ShowLayoutBounds”的 SS 时,我注意到我正在为按钮本身而不是其持续布局设置动画,因此布局正在剪切按钮。我只是让它动画相对布局,一切都很好。 \m/(>
    • @Nerves,已更新。在这种情况下,“显示布局绑定”可能与您同在:-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 2020-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-03
    • 1970-01-01
    相关资源
    最近更新 更多