android 点击图片放大 ,再次点击恢复原样
在这里我使用再启动一个activity实现的,并且归并了一组图片不在需要做n个activity 那样麻烦
首先是一组图片放在一个activity里面
public ImageLoader imageLoader;
private ImageView ivImg1;
private ImageView ivImg2;
private ImageView ivImg3;
private ImageView ivImg4;
ivImg1 = (ImageView) findViewById(R.id.ivImg1);
ivImg1.setOnClickListener(this);
ivImg2 = (ImageView) findViewById(R.id.ivImg2);
ivImg2.setOnClickListener(this);
ivImg3 = (ImageView) findViewById(R.id.ivImg3);
ivImg3.setOnClickListener(this);
ivImg4 = (ImageView) findViewById(R.id.ivImg4);
ivImg4.setOnClickListener(this);
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.ivImg1:
Intent intentx1=new Intent(this,ShopDaImageActivity.class);
int a=1;
intentx1.putExtra("id", a);
intentx1.putExtra("ShopView",shopview);
startActivity(intentx1);
break;
case R.id.ivImg2:
Intent intentx2=new Intent(this,ShopDaImageActivity.class);
int b=2;
intentx2.putExtra("id", b);
intentx2.putExtra("ShopView",shopview);
startActivity(intentx2);
break;
case R.id.ivImg3:
Intent intentx3=new Intent(this,ShopDaImageActivity.class);
int c=3;
intentx3.putExtra("id", c);
intentx3.putExtra("ShopView",shopview);
startActivity(intentx3);
break;
case R.id.ivImg4:
Intent intentx4=new Intent(this,ShopDaImageActivity.class);
int d=4;
intentx4.putExtra("id", d);
intentx4.putExtra("ShopView",shopview);
startActivity(intentx4);
break;
用bundle在activity之间传递数据
然后进入ShopDaImageActivity.java布局里面放置一个imageview
private ImageView image_da;
private ShopBean shopview;
public ImageLoader imageLoader;
image_da=(ImageView)findViewById(R.id.image_da);
image_da.setOnClickListener(this);
Intent intent=getIntent();
int e=intent.getIntExtra("id", 0);
switch (e) {
case 1:
shopview=(ShopBean)intent.getSerializableExtra("ShopView");
imageLoader = new ImageLoader(getApplicationContext());
imageLoader.DisplayImage(shopview.getShare().getImg() + "!small.jpg", image_da);
break;
case 2:
shopview=(ShopBean)intent.getSerializableExtra("ShopView");
imageLoader = new ImageLoader(getApplicationContext());
imageLoader.DisplayImage(shopview.getShare().getImg2() + "!small.jpg", image_da);
break;
case 3:
shopview=(ShopBean)intent.getSerializableExtra("ShopView");
imageLoader = new ImageLoader(getApplicationContext());
imageLoader.DisplayImage(shopview.getShare().getImg3() + "!small.jpg", image_da);
break;
case 4:
shopview=(ShopBean)intent.getSerializableExtra("ShopView");
imageLoader = new ImageLoader(getApplicationContext());
imageLoader.DisplayImage(shopview.getShare().getImg4() + "!small.jpg", image_da);
break;
default:
break;
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.image_da:
ShopDaImageActivity.this.finish();
break;
default:
break;
}
}
大家可能看不懂ShopBean 其实是一个类,里面包含了各种信息包括图片,这里我只是取了里面的图片
单独来出来讲下的