0
我試圖將我的視圖製作爲父視圖外部的視圖。正如其他問題所述,我需要使用:使用卡片視圖從父級佈局邊界創建動畫視圖
android:clipChildren="false"
android:clipToPadding="false"
這對於普通視圖來說是完美的!不過,我需要爲CardView生成一個視圖。出於某種原因,當我的視圖位於CardView中時,它不會生成動畫,它只會停留在邊框處。
我的佈局文件是非常簡單的,只是一個LinearLayout中,一些看法並與裏面的動畫視cardview:
<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和動畫了嗎?
需要min API 21,我需要API 16的解決方案 –