使imageview显示在fullScreen上

时间:2012-05-29 04:13:12

标签: android

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

使用webviews是一个更好的选择吗?

代码:     package 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);

        }


    }



}

2 个答案:

答案 0 :(得分: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;
                    }

    }

}

答案 1 :(得分:0)

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

在新的活动中显示您所说的图像:为了传递图像的价值,您还可以使用共享偏好或意图:祝您好运