0
我是android新手。我有像陣列:如何知道在android中點擊圖像的索引?
private int[] textureArrayWin = {
R.drawable.basketball,
R.drawable.soccer
};
嘗試動態將它們添加到我的觀點:
for(int i=0; i < textureArrayWin.length; i++){
Log.v("asd", "index=" + i);
ImageView tv = new ImageView(this);
tv.setScaleType(ScaleType.CENTER_CROP);
tv.setImageResource(textureArrayWin[i]);
tv.setAdjustViewBounds(true);
tv.setMaxHeight(20);
tv.setMaxWidth(20);
myLayout.addView(tv);
}
但不知道如何:
- 適合他們通過「setMaxHeight」,它們仍然很大
- 如何知道數組中點擊圖像的索引或t o接收一些圖像的ID,以便在我的佈局中知道圖像的唯一ID。例如,在javascript中,我可以通過將「at.getAttribute(someAttr)」添加到元素和處理程序接收屬性中來實現。