使用 CardView 为超出父布局边界的视图设置动画
Animating view out of parent layout bounds with a CardView
我正在尝试将我的视图动画化为父布局之外的视图。正如其他问题所述,我需要使用:
android:clipChildren="false"
android:clipToPadding="false"
这非常适合普通视图!但是,我需要为 CardView 之外的视图设置动画。出于某种原因,当我的视图在 CardView 内部时,它不会从中动画出来,它只是停在边界处。
我的布局文件非常简单,只有一个 LinearLayout、一些视图和一个带有动画视图的卡片视图:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:clipChildren="false"
android:clipToPadding="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<android.support.v7.widget.CardView
android:layout_width="350dp"
android:layout_height="200dp"
android:clipChildren="false"
android:clipToPadding="false">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false">
<View
android:id="@+id/animate"
android:layout_width="25dp"
android:layout_height="25dp"
android:background="@android:color/holo_red_light"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
我用于动画的代码是:
View view = findViewById(R.id.animate);
ObjectAnimator animation2 = ObjectAnimator.ofFloat(view, "translationY", -500);
animation2.setDuration(5000);
animation2.setTarget(view);
animation2.start();
现在的问题是,当我使用 CardView 时,视图在边框处停止动画。它只是消失了。当我使用普通的 FrameLayout 时,它会在父级之外设置动画。
CardView 和动画中是否遗漏了任何奇怪的行为?
原来在CardView上
cardView.setClipToOutline(false);
需要打电话。这确实可以防止物品在边界处消失。
我正在尝试将我的视图动画化为父布局之外的视图。正如其他问题所述,我需要使用:
android:clipChildren="false"
android:clipToPadding="false"
这非常适合普通视图!但是,我需要为 CardView 之外的视图设置动画。出于某种原因,当我的视图在 CardView 内部时,它不会从中动画出来,它只是停在边界处。
我的布局文件非常简单,只有一个 LinearLayout、一些视图和一个带有动画视图的卡片视图:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:clipChildren="false"
android:clipToPadding="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<android.support.v7.widget.CardView
android:layout_width="350dp"
android:layout_height="200dp"
android:clipChildren="false"
android:clipToPadding="false">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false">
<View
android:id="@+id/animate"
android:layout_width="25dp"
android:layout_height="25dp"
android:background="@android:color/holo_red_light"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
我用于动画的代码是:
View view = findViewById(R.id.animate);
ObjectAnimator animation2 = ObjectAnimator.ofFloat(view, "translationY", -500);
animation2.setDuration(5000);
animation2.setTarget(view);
animation2.start();
现在的问题是,当我使用 CardView 时,视图在边框处停止动画。它只是消失了。当我使用普通的 FrameLayout 时,它会在父级之外设置动画。
CardView 和动画中是否遗漏了任何奇怪的行为?
原来在CardView上
cardView.setClipToOutline(false);
需要打电话。这确实可以防止物品在边界处消失。