我创建了一个 Android 百家乐游戏。我总共有六张牌,每个玩家显示三张。早些时候,我在使用该应用程序时,每张牌都正确显示,现在玩家的第二张和第三张牌已经交换了位置,我没有更改我的代码中的任何内容。
<ImageView
android:id="@+id/PlayerCard2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/PlayerCardsTotalText"
android:layout_alignLeft="@+id/TieBetTotalText"
android:layout_alignParentBottom="false"
android:contentDescription="@string/PlayerCard2Image"
android:src="@drawable/b1fv" />
<ImageView
android:id="@+id/PlayerCard3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/PlayerCardsTotalText"
android:layout_alignParentRight="true"
android:contentDescription="@string/PlayerCard3Image"
android:src="@drawable/b1fv" />
这是球员卡的 XML 代码。 PlayerCard2 和 PlayerCard3 是已经切换的。
PlayerCardImage2.setImageResource(deckOfCards[PlayerCard+ generateSuit()]);
这是根据数组中随机选择的数字更新图像的 java 代码。
我试过交换卡片的位置,但我仍然得到相同的结果。
PlayerCardImage1 = (ImageView)findViewById(R.id.PlayerCard1);
PlayerCardImage2 = (ImageView)findViewById(R.id.PlayerCard2);
PlayerCardImage3 = (ImageView)findViewById(R.id.PlayerCard3);
这是我引用 Activity 图像的地方。
最佳答案
听起来像自动生成的 R
类被搞砸了,这种情况偶尔会发生。
您应该清理您的项目 - 在 Eclipse 中:项目 -> 清理... -> 检查您的项目。这也将触发 R
的重新创建,应该可以解决您的问题。
关于java - 错误的 ImageView 正在更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16331941/