从我在我的应用程序中使用ImageView,如下面的代码
ImageView menu=(ImageView)findViewById(R.id.imageView1);
@Override
public void onclick(View v)
{
int id = v.getId();
if(id==R.id.imageView1)
{
if (menuopen.getVisibility() == View.VISIBLE) {
menuopen.setVisibility(View.GONE);
menu.setImageResource(R.drawable.menu_close_image);
} else {
menuopen.setVisibility(View.VISIBLE);
menu.setImageResource(R.drawable.menu_open_image);
}
}
}
在上面的代码中,基于菜单打开我正在更改可绘制资源中的图像,同时这样做我想知道屏幕中当前可见的图像。如何找到?
我想在代码中的其他位置使用图像信息。
答案 0 :(得分:0)
you can have it like this
ImageView menu=(ImageView)findViewById(R.id.imageView1);
@Override
public void onclick(View v)
{
int id = v.getId();
if(id==R.id.imageView1)
{
if (menuopen.getVisibility() == View.VISIBLE) {
menuopen.setVisibility(View.GONE);
menu.setImageResource(R.drawable.menu_close_image);
mCurrentImage=R.drawable.menu_close_image
} else {
menuopen.setVisibility(View.VISIBLE);
menu.setImageResource(R.drawable.menu_open_image);
mCurrentImage=R.drawable.menu_open_image
}
}
}
答案 1 :(得分:0)
试试如下:
ImageView menu=(ImageView)findViewById(R.id.imageView1);
@Override
public void onclick(View v)
{
switch(v.getId())
{
case R.id.imageView1:
if (menuopen.getVisibility() == View.VISIBLE) {
menuopen.setVisibility(View.GONE);
menu.setImageResource(R.drawable.menu_close_image);
} else if (menuopen.getVisibility() == View.INVISIBLE) {
menuopen.setVisibility(View.VISIBLE);
menu.setImageResource(R.drawable.menu_open_image);
}
break;
}
}
答案 2 :(得分:0)
private int[] imageArray = {
R.drawable.image1,
R.drawable.image2
};
//将此图像设置为该imageview(菜单)的id
menu.setId(imageArray[i]);
//然后在onclick
if(menu.getId==R.drawable.image1{
//image1 is displaying
}else{
//image2 is displaying
}