2 xiang7478728 xiang7478728 于 2014.04.02 18:23 提问

android程序运行的时候出现unfortunately,imageView has stopped.

xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.android.imageview.MainActivity"
tools:ignore="MergeRootFrame" >
android:id="@+id/imageView"
android:layout_width="250dp"
android:layout_height="300dp"
android:src="@drawable/image"
android:contentDescription="@string/description"
android:scaleType="fitCenter">
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/text_one"/>
android:id="@+id/seekBar1"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:max="300"
android:progress="100"
android:layout_marginTop="10dp"/>
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/text_two"
android:layout_marginTop="10dp">
android:id="@+id/seekBar2"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:max="360"
android:layout_marginTop="10dp"/>

package com.android.imageview;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.os.Build;

public class MainActivity extends ActionBarActivity implements OnSeekBarChangeListener{

private int minWidth = 40;
private TextView textView1,TextView2;
private ImageView imageView;
private Matrix matrix;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    imageView = (ImageView)this.findViewById(R.id.imageView);
    SeekBar seekBar1 = (SeekBar)this.findViewById(R.id.seekBar1);
    SeekBar seekBar2 = (SeekBar)this.findViewById(R.id.seekBar2);
    seekBar1.setOnSeekBarChangeListener(this);
    seekBar2.setOnSeekBarChangeListener(this);

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);

    seekBar1.setMax(dm.widthPixels-minWidth);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
        boolean fromUser) {
    // TODO Auto-generated method stub
    if (seekBar.getId()==R.id.seekBar1){
        int newWidth = progress + minWidth;
        int newHeight = (int)(newWidth*6/5);
        imageView.setLayoutParams(new LinearLayout.LayoutParams(newWidth, newHeight));
        textView1.setText("图像宽度:"+newWidth+"  图像高度:"+newHeight);
    }else if(seekBar.getId()==R.id.seekBar2){
        Bitmap bitmap = ((BitmapDrawable)getResources().getDrawable(R.drawable.image)).getBitmap();
        matrix.setRotate(progress);
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        imageView.setImageBitmap(bitmap);
        TextView2.setText(progress+"度");
    }

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!