我知道有人对此主题有疑问,但没有帮助我.
我正在制作纸牌游戏(通常称为集中或记忆游戏),每当选择两张相同的纸牌时,我都希望它们使用TranslateAnimation到达顶部.问题是,视图位于其他布局和视图下…
这是函数:
private voID matchAnimation(int card1ID, int card2ID ,boolean isPlayer1) { getnameLocations(); int x; int[] card1Loc = new int[2]; int[] card2loc = new int[2]; ImageVIEw card1 = (ImageVIEw)findVIEwByID(card1ID); ImageVIEw card2 = (ImageVIEw)findVIEwByID(card2ID); if (player) x = playerOneLocation[0]; else x = playerTwolocation[0]; card1.getLocationOnScreen(card1Loc); card2.getLocationOnScreen(card2loc); Animation animationMove = new TranslateAnimation(0, x-card1Loc[0], 0, playerOneLocation[1]-card1Loc[1]); animationMove.setZAdjustment(Animation.ZORDER_top); animationMove.setDuration(1000); animationMove.setFillAfter(true); card1.startAnimation(animationMove); card2.startAnimation(animationMove); card1.setVisibility(VIEw.VISIBLE);}
这是XML:
<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools="http://schemas.androID.com/tools"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"androID:background="#BDE1FF"androID:paddingBottom="@dimen/activity_vertical_margin"androID:paddingleft="@dimen/activity_horizontal_margin"androID:paddingRight="@dimen/activity_horizontal_margin"androID:paddingtop="@dimen/activity_vertical_margin"tools:context=".GamePlay" ><tableLayout androID:ID="@+ID/tableLayout1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParentBottom="true" androID:layout_marginBottom="@dimen/activity_vertical_margin" androID:layout_centerHorizontal="true" > <tableRow androID:ID="@+ID/tableRow1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_margintop="8dp" > <ImageVIEw androID:ID="@+ID/c1" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_1" /> <ImageVIEw androID:ID="@+ID/c2" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_2" /> <ImageVIEw androID:ID="@+ID/c3" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_3" /> <ImageVIEw androID:ID="@+ID/c4" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_4" /> </tableRow> <tableRow androID:ID="@+ID/tableRow2" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_margintop="8dp"> <ImageVIEw androID:ID="@+ID/c5" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_5" /> <ImageVIEw androID:ID="@+ID/c6" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_6" /> <ImageVIEw androID:ID="@+ID/c7" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_7" /> <ImageVIEw androID:ID="@+ID/c8" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_8" /> </tableRow> <tableRow androID:ID="@+ID/tableRow3" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_margintop="8dp"> <ImageVIEw androID:ID="@+ID/c9" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_9" /> <ImageVIEw androID:ID="@+ID/c10" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_10" /> <ImageVIEw androID:ID="@+ID/c11" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_11" /> <ImageVIEw androID:ID="@+ID/c12" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_12" /> </tableRow> <tableRow androID:ID="@+ID/tableRow4" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_margintop="8dp" > <ImageVIEw androID:ID="@+ID/c13" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_13" /> <ImageVIEw androID:ID="@+ID/c14" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_14" /> <ImageVIEw androID:ID="@+ID/c15" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_15" /> <ImageVIEw androID:ID="@+ID/c16" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_16" /> </tableRow> <tableRow androID:ID="@+ID/tableRow5" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_margintop="8dp" > <ImageVIEw androID:ID="@+ID/c17" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_17" /> <ImageVIEw androID:ID="@+ID/c18" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_18" /> <ImageVIEw androID:ID="@+ID/c19" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_19" /> <ImageVIEw androID:ID="@+ID/c20" androID:onClick="cardPicked" androID:src="@drawable/icon" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:contentDescription="@string/card_20" /> </tableRow></tableLayout> <TextVIEw androID:ID="@+ID/playername1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParentRight="true" androID:layout_alignParenttop="true" androID:layout_margintop="4dp" androID:layout_marginRight="12dp" androID:text="@string/placeholder" androID:textAppearance="?androID:attr/textAppearanceLarge" /> <TextVIEw androID:ID="@+ID/playername2" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParentleft="true" androID:layout_alignParenttop="true" androID:layout_margintop="4dp" androID:layout_marginleft="12dp" androID:text="@string/placeholder" androID:textAppearance="?androID:attr/textAppearanceLarge" /> <TextVIEw androID:ID="@+ID/playerscore2" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignBaseline="@+ID/playerscore1" androID:layout_alignBottom="@+ID/playerscore1" androID:layout_alignleft="@+ID/tableLayout1" androID:text="@string/initial_score" androID:textAppearance="?androID:attr/textAppearanceMedium" androID:textStyle="bold" /> <ImageVIEw androID:ID="@+ID/pointer" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_aligntop="@+ID/playername1" androID:layout_centerHorizontal="true" androID:contentDescription="@string/smurf_pointing" androID:src="@drawable/smurf" /> <TextVIEw androID:ID="@+ID/playerscore1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignRight="@+ID/tableLayout1" androID:layout_below="@+ID/playername1" androID:text="@string/initial_score" androID:textAppearance="?androID:attr/textAppearanceMedium" androID:textStyle="bold" />
希望有人能帮忙!谢谢.
解决方法:
将androID:clipChildren =“ false”设置为所有容器布局.
另请参阅我的问题:Animation: Move TextView into another container.
但是,我注意到这导致AndroID 2.3版中的布局出现问题.
所以我现在想做的是在所有动画发生的位置创建一个自己的VIEwOverlay.
根据您要支持的版本,还有一个VIEw.getVIEwOverlay()
总结以上是内存溢出为你收集整理的Android翻译动画位于布局和视图下全部内容,希望文章能够帮你解决Android翻译动画位于布局和视图下所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)