我的活动包含String
数组,每个String
都是drawable
图像名称,例如,如果我有一个名为" abcd"然后在String
数组中,第一个值将是" abcd"。我试图将此String
数组传递给另一个活动,然后显示所有图像。
第一项活动:
Intent ip = new Intent(main3.this, main4.class);
ip.putExtra("p", usedcards1);
startActivity(ip);
第二项活动:
ImageView[] usedcardss;
RelativeLayout rel = (RelativeLayout) findViewById(R.id.main4con);
usedcardss = new ImageView[8];
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
for (int i = 0; i < usedcardss.length; i++)
usedcardss[i] = new ImageView(this);
Intent pp = this.getIntent();
String[] cards = pp.getStringArrayExtra("p");
for (int i = 0; i < 8; i++) {
int icon = getResources().getIdentifier(cards[i], "drawable", getPackageName());
usedcardss[i].setImageResource(icon);
usedcardss[i].setLayoutParams(lp);
rel.addView(usedcardss[i]);
}
创建了一个新活动,但它只是空白。为什么呢?
答案 0 :(得分:1)
可能与您的问题没有直接关系,但是您使用的是相对布局,我在您的代码中没有看到您正在设置图像布局参数,这会导致imageViews重叠