2013-01-02 96 views
0

我有一个纸牌游戏,其中卡片被表示为布局对象,其包含具有卡片的背景图像的大切换按钮,以及代表等级和花色的文本视图卡。布局动画时不显示Android布局文本

<RelativeLayout 
      android:id="@+id/card1"> 
     <ToggleButton 
       android:id="@+id/cardback1" android:background="@drawable/blank_card" android:checked="false" android:textOff='' android:textOn="HELD" android:textColor="@android:color/holo_red_dark" android:clickable="true" android:enabled="false"/> 
     <TextView 
       android:id="@+id/rank1" 
       android:textColor="@android:color/holo_red_light" 
       android:textIsSelectable="false" 
       android:textSize="16dp" 
       android:layout_alignParentTop="true" android:layout_marginTop="5dp" 
       android:layout_marginLeft="7dp" android:textAlignment="center"/> 
     <TextView 
       android:id="@+id/suit1" android:text="@string/suit_diamond" 
       android:textColor="@android:color/holo_red_light" 
       android:textIsSelectable="false" android:typeface="normal" 
       android:textSize="24dp" 
       android:layout_centerInParent="true"/> 
</RelativeLayout> 

当redealing卡我想申请一个自定义动画,显示卡为“翻转”这是我在一系列对象的动画师正在做,Y轴旋转 我使用的动画师等定义:

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" 
     android:valueFrom="0" android:valueTo="360" android:propertyName="rotationY" > </objectAnimator> 

然后我在布局xml中引用的RelativeLayout动画。

RelativeLayout cardLayout = (RelativeLayout)findViewById(R.id.card1); 
Animator initialAnimator = (ObjectAnimator) AnimatorInflater.loadAnimator(cardLayout.getContext(), R.anim.flip360); 
    initialAnimator.setTarget(cardLayout); 
    initialAnimator.setDuration(1000); 
    initialAnimator.start(); 

但是,在动画过程中,布局上的任何文本都没有显示出来。按钮图像按预期方式旋转,但文字在动画完成之前不显示。

我之前在cardLayout上使用了更简单的动画,只是在Y轴上缩放以模拟旋转,但它看起来不太好。但是,使用该方法时,动画期间文本仍然显示在卡上。有什么我需要配置,以便文本可以显示在卡上,并与图像一起动画,还是我需要分别添加自定义动画到卡的所有元素?

回答

1

我认为在经历Android API documentation时我自己偶然发现了答案,所以我想我只是在这里发帖以防有人出现同样的问题。

通过调用动画之前使drawingCache:

cardLayout.setDrawingCacheEnabled(true); 

我得到的布局呈现为位图,它开始动画,其中包括包含在布局内的案文。