android bundle 在activity之间传递数据 点击一组图片放大,再次点击恢复

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 其实是一个类,里面包含了各种信息包括图片,这里我只是取了里面的图片

单独来出来讲下的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值