android 显示大图片

//MianActivity

android 显示大图片
package com.example.showsmallandbigpic;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Display;
import android.widget.ImageView;

public class picActivity extends Activity {
    private ImageView ivTest;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pic);
        ivTest=(ImageView)findViewById(R.id.iv);
        Intent intent=getIntent();
        String s=intent.getStringExtra("type");
        if(s.equals("small")){
            Bitmap bm=BitmapFactory.decodeResource(getResources(), R.drawable.small);
            ivTest.setImageBitmap(bm);
        }
        else{
            Display currenDisplay=getWindowManager().getDefaultDisplay();
            int dw=currenDisplay.getWidth();
            int dh=currenDisplay.getHeight();
            BitmapFactory.Options bmpFactoryOptions=new BitmapFactory.Options();
            bmpFactoryOptions.inJustDecodeBounds=true;        
            Bitmap bmpBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.big,bmpFactoryOptions);
            int heightRatio=(int)Math.ceil(bmpFactoryOptions.outHeight/(float)dh);
            int widthRatio=(int)Math.ceil(bmpFactoryOptions.outWidth/(float)dw);
            System.out.println("heightRation="+heightRatio);
            System.out.println("widthRatio="+widthRatio);            
            if(heightRatio>1&&widthRatio>1){
                if (heightRatio>widthRatio)
                    bmpFactoryOptions.inSampleSize=heightRatio;
            
            else {
                bmpFactoryOptions.inSampleSize=widthRatio;
            }
            }
            bmpFactoryOptions.inJustDecodeBounds=false;
            Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.big,bmpFactoryOptions);
            ivTest.setImageBitmap(bmp);
            
        }
    }
    

}
android 显示大图片

//picActivity

android 显示大图片
package com.example.showsmallandbigpic;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Display;
import android.widget.ImageView;

public class picActivity extends Activity {
    private ImageView ivTest;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pic);
        ivTest=(ImageView)findViewById(R.id.iv);
        Intent intent=getIntent();
        String s=intent.getStringExtra("type");
        if(s.equals("small")){
            Bitmap bm=BitmapFactory.decodeResource(getResources(), R.drawable.small);
            ivTest.setImageBitmap(bm);
        }
        else{
            Display currenDisplay=getWindowManager().getDefaultDisplay();
            int dw=currenDisplay.getWidth();
            int dh=currenDisplay.getHeight();
            BitmapFactory.Options bmpFactoryOptions=new BitmapFactory.Options();
            bmpFactoryOptions.inJustDecodeBounds=true;        
            Bitmap bmpBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.big,bmpFactoryOptions);
            int heightRatio=(int)Math.ceil(bmpFactoryOptions.outHeight/(float)dh);
            int widthRatio=(int)Math.ceil(bmpFactoryOptions.outWidth/(float)dw);
            System.out.println("heightRation="+heightRatio);
            System.out.println("widthRatio="+widthRatio);            
            if(heightRatio>1&&widthRatio>1){
                if (heightRatio>widthRatio)
                    bmpFactoryOptions.inSampleSize=heightRatio;
            
            else {
                bmpFactoryOptions.inSampleSize=widthRatio;
            }
            }
            bmpFactoryOptions.inJustDecodeBounds=false;
            Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.big,bmpFactoryOptions);
            ivTest.setImageBitmap(bmp);
            
        }
    }
    

}

android 显示大图片

//activity_main.xml

android 显示大图片
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/small"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="107dp"
        android:layout_marginTop="103dp"
        android:text="small" />

    <Button
        android:id="@+id/big"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/small"
        android:layout_centerVertical="true"
        android:text="big" />

</RelativeLayout>
android 显示大图片

//pic.xml

android 显示大图片
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/iv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/ic_launcher" />
</RelativeLayout>
android 显示大图片

 

android 显示大图片,布布扣,bubuko.com

android 显示大图片

上一篇:ios学习记录 day30 UI 8 协议 滚动视图


下一篇:CosCos-android 代码总结