在android应用程序中将一系列图像放大到线性布局
我正在开发一款blackjack Android应用程序,我正在使用这种方法来放大卡片图像。我使用卡的值来确定要加载的图像以及要知道要将其添加到哪个ImageView的索引。我称之为玩家手中的每张牌。第一张卡片显示,但之后没有显示。我检查了日志,第二张卡的图像名称和位置正确无误在android应用程序中将一系列图像放大到线性布局,android,android-imageview,layout-inflater,blackjack,Android,Android Imageview,Layout Inflater,Blackjack,我正在开发一款blackjack Android应用程序,我正在使用这种方法来放大卡片图像。我使用卡的值来确定要加载的图像以及要知道要将其添加到哪个ImageView的索引。我称之为玩家手中的每张牌。第一张卡片显示,但之后没有显示。我检查了日志,第二张卡的图像名称和位置正确无误 for(int i = 0; i < playerHand.getCardCount(); i++) { addPlayerCardImage(playerHand.getCardByIndex(i), i);
for(int i = 0; i < playerHand.getCardCount(); i++)
{
addPlayerCardImage(playerHand.getCardByIndex(i), i);
}
private void addPlayerCardImage(Card pCard, int cardIndex)
{
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
cardImageView = inflater.inflate(R.layout.cardlayout, playerhandlayout , false);
String selectedImage = "card" + pCard.getValue() + pCard.getSuitAsCharacter();
int CardImageID = getResources().getIdentifier(selectedImage, "drawable",getPackageName());
Log.d("FLAG", "Card " + selectedImage);
String cardLocation = "imageViewCard" + cardIndex;
int cardLocationID = getResources().getIdentifier(cardLocation, "id",getPackageName());
Log.d("FLAG", "Card location " + cardLocation);
ImageView cardImage = (ImageView) cardImageView.findViewById(cardLocationID);
cardImage.setImageResource(CardImageID);
playerhandlayout.addView(cardImageView);
}
for(int i=0;i
这是一个XML布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageViewCard0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:src="@drawable/cardback" />
<ImageView
android:id="@+id/imageViewCard1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:src="@drawable/cardback" />
<ImageView
android:id="@+id/imageViewCard2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:src="@drawable/cardback" />
<ImageView
android:id="@+id/imageViewCard3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:src="@drawable/cardback" />
<ImageView
android:id="@+id/imageViewCard4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:src="@drawable/cardback" />
</LinearLayout>
playerhandlayout xml
<LinearLayout
android:id="@+id/playerhandlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
上述代码仅显示一张卡。。代码的其余部分在哪里?您是否可以包含playerhandlayout
的xml,以便我们可以检查它与水平布局不同,而布局应该是垂直的或类似的?嗯,您设置cardLocationId
的方式似乎使xml中的每张卡都有一个ImageView
。但那你为什么要多次充气呢?每一张卡不都有四张卡片imageview
?我假设最近添加的XML是R.layout.cardlayout
。在XML中,playerhandlayout
看起来像什么?playerhandlayout是主游戏布局中的水平线性布局