我想提出一個漢字卡片應用兩個視圖之間卡翻轉動畫。我想要有一個LinearLayout
代表正面,另一個代表卡的背面,我已經在一個XML佈局中聲明。 問題是,所述第二LinearLayout
總是不可見的,第一個正常的動畫。 無論如何要在動畫正在進行時進行方法調用嗎?我想將第一個佈局的可見性設置爲GONE
,第二個設置爲VISIBLE
?實現使用AnimatorSet
還是有實現翻轉卡的另一個更好的辦法?
以下是我的代碼。預先感謝。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_container_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ff825e4e" >
<LinearLayout
android:id="@+id/card_front_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:gravity="center"
android:background="@drawable/card_shape_front">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="傘"
android:textColor="#ff000000"
android:textSize="200sp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/card_back_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_margin="10dp"
android:background="@drawable/card_shape_front">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="QWERTY"
android:textColor="#ff000000"/>
</LinearLayout>
</LinearLayout>
FlashcardsFragment.java
public class FlashcardsFragment extends Fragment
{
private AnimatorSet showFrontAnim = new AnimatorSet();
private AnimatorSet showBackAnim = new AnimatorSet();
private boolean isShowingBack = false;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.fragment_flashcard, container, false);
LinearLayout cardFront = (LinearLayout) v.findViewById(R.id.card_front_layout);
LinearLayout cardBack = (LinearLayout) v.findViewById(R.id.card_back_layout);
// Load the animator sets from XML and group them together
AnimatorSet leftIn = (AnimatorSet) AnimatorInflater
.loadAnimator(getActivity(), R.animator.card_flip_left_in);
AnimatorSet rightOut = (AnimatorSet) AnimatorInflater
.loadAnimator(getActivity(), R.animator.card_flip_right_out);
AnimatorSet leftOut = (AnimatorSet) AnimatorInflater
.loadAnimator(getActivity(), R.animator.card_flip_left_out);
AnimatorSet rightIn = (AnimatorSet) AnimatorInflater
.loadAnimator(getActivity(), R.animator.card_flip_right_in);
leftIn.setTarget(cardFront);
rightOut.setTarget(cardBack);
showFrontAnim.playTogether(leftIn, rightOut);
leftOut.setTarget(cardFront);
rightIn.setTarget(cardBack);
showBackAnim.playTogether(leftOut, rightIn);
LinearLayout cardContainer = (LinearLayout)
v.findViewById(R.id.card_container_layout);
// Set the flip animation to be triggered on container clicking
cardContainer.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if (isShowingBack) {
showFrontAnim.start();
isShowingBack = false;
}
else {
showBackAnim.start();
isShowingBack = true;
}
}
});
return v;
}
}
謝謝,但我想知道的是如何插入而那些意見是動畫調用。 – kradragon 2014-10-04 10:52:57
@kradragon你可以嘗試playTogether方法... – tibuurcio 2014-10-04 10:54:51
因爲動畫還沒有開始這將無法正常工作後給他們打電話。我想在半動畫時間更改視圖。 – kradragon 2014-10-04 11:04:36