我正在开发纸牌游戏。我使用服务器将13张卡分成每个客户端, 当我将13张牌分成第1张牌时,9张牌是看不见的,其余4张是可见的。 现在我想要点击这一张图片,其余9张卡片可见吗? 这该怎么做? - 代码是这样的:
String str=" "c,a", "c,k", "c,q", "c,j", "c,10", "c,9", "c,8", "c,7", "c,6", "c,5", "c,4", "c,3", "c,2"";
drawCards(str);
private void drawCards(String drawString) {
String[] separated = msgLog.split("\\,");
for (int i = 2; i < separated.length - 1; i += 2) {
String symbol = separated[i];
String num = separated[i + 1];
String resourceName = symbol + num;
//symbol and number is used for get image from xml file
int resID = getResources().getIdentifier(resourceName, "id", getPackageName());
im = (ImageView) findViewById(resID);
Context context = im.getContext();
cardID = context.getResources().getIdentifier(resourceName, "drawable", context.getPackageName());
//9 card invisible
if ( i > 10) {
im.setVisibility(View.GONE);
}
/* elseif(x.getVisibility() == VISIBLE)
{
x.setVisibility(INVISIBLE);
}*/
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(im.getLayoutParams());
lp.setMargins(counter * 5, 0, 0, 0);//left,right,top,bottom
im.setLayoutParams(lp);
im.setImageResource(cardID);
im.setOnClickListener(this);
counter = counter + 8;
}
}
public void onClick(View v) {
final String IdAsString = v.getResources().getResourceName(v.getId());
pieceToast = Toast.makeText(getApplicationContext(), idServer, Toast.LENGTH_SHORT);
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
pieceToast.show();
}
});
}
当我点击此卡时如何隐藏卡片可见
答案 0 :(得分:1)
您可以从下面给定的链接中获取帮助:
https://stackoverflow.com/questions/41285814/how-to-make-visible-and-invisible-an-image-by-clicking-a-button-in-android-studi
如果你还有问题,请告诉我
答案 1 :(得分:0)
您可以使用可见性并使用方法setVisibility(View.VISIBLE)
和setVisibility(View.GONE)