1

我在一个活动中有 4 个图像视图,我希望如果用户单击任何图像.. 图像应该弹出并全屏显示.. 我怎么能做到这一点?

使用 webviews 是更好的选择吗?

代码:包com.integrated.mpr;

import java.io.File;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.widget.ImageView;
import android.widget.TextView;

public class FinalShow extends Activity{



    ImageView iva;
    ImageView ivb;
    ImageView ivc;
    ImageView ivd;

    File folder = null;


    Model model = new Model();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.finalshow);



        iva = (ImageView) findViewById(R.id.iva);
        ivb = (ImageView) findViewById(R.id.ivb);
        ivc = (ImageView) findViewById(R.id.ivc);
        ivd = (ImageView) findViewById(R.id.ivd);



        String sdcardstate = android.os.Environment.getExternalStorageState();

        if(sdcardstate.contentEquals(android.os.Environment.MEDIA_MOUNTED)){

            String filepath = Environment.getExternalStorageDirectory().getPath();
            folder = new File(filepath,model.s);//model.s contains the name of folder

            File fa = new File(folder,"bmp1.png");
            Bitmap bmpa = BitmapFactory.decodeFile(fa.getAbsolutePath());
            iva.setImageBitmap(bmpa);

            File fb = new File(folder,"bmp2.png");
            Bitmap bmpb = BitmapFactory.decodeFile(fb.getAbsolutePath());
            ivb.setImageBitmap(bmpb);


            File fc = new File(folder,"bmp3.png");
            Bitmap bmpc = BitmapFactory.decodeFile(fc.getAbsolutePath());
            ivc.setImageBitmap(bmpc);


            File fd = new File(folder,"bmp4.png");
            Bitmap bmpd = BitmapFactory.decodeFile(fd.getAbsolutePath());
            ivd.setImageBitmap(bmpd);

        }


    }



}
4

2 回答 2

5

创建一个在开始时不可见的图像视图(给出父级的完整高度和宽度)。单击任何图像时,将图像设置为此新的图像视图并使其可见。

首先确保新添加的 imageview 覆盖了整个高度和宽度。更好的是,您使用相对布局

<?xml version="1.0" encoding="utf-8"?>

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="14dp"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="16dp"
    android:layout_toRightOf="@+id/imageView1"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/imageView1"
    android:layout_below="@+id/imageView1"
    android:layout_marginTop="19dp"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/imageView2"
    android:layout_alignTop="@+id/imageView3"
    android:src="@drawable/ic_launcher" />

<ImageView android:id="@+id/fullview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/ic_launcher"
    android:visibility="gone"/>

在java代码中,

      firstImageView.setOnclickListener(new ClickListener());
      secondImageView.setOnclickListener(new ClickListener());
      thirdImageView.setOnclickListener(new ClickListener());
      fourthImageView.setOnclickListener(new ClickListener());



 class ClickListener implements OnClickListener {

    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()) {
                     case R.id.firstimage: // set image to fullimageview; break;
                      case R.id.secondimage:// set this image to fullimage break;
                    }

    }

}
于 2012-05-29T04:40:22.763 回答
0

做一件事做一个新的活动:然后在图像点击调用另一个活动之间你可以添加动画弹出:

如您所说,在新活动中显示您的图像:对于图像的传递值,您也可以使用共享首选项或意图:祝您好运

于 2012-05-29T04:40:41.900 回答