我有一个包含图像的 ImageView。此图像通过按钮单击旋转,但有时它会变小或恢复其原始大小。我不知道是什么原因造成的。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >
    //tablelayout here
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true" 
        android:layout_centerVertical="true"
        android:orientation="vertical" >
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:maxWidth="200dp" 
        android:maxHeight="200dp"
         /> 
    </LinearLayout>
</RelativeLayout>
初始设置:
 iv = (ImageView)findViewById(R.id.imageView1);
        int id = getResources().getIdentifier("landolt", "drawable", getPackageName());
        iv.setImageResource(id);
        myImg = BitmapFactory.decodeResource(getResources(), R.drawable.landolt);
        matrix = new Matrix();
        size = 200;
        randomize = new Random();
        random = randomize.nextInt(8) + 1;
        rotate = getAngle(random);  //function created by me
        matrix.postRotate(rotate);
        rotatedBitmap = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(), myImg.getHeight(), matrix, true);
        iv.setImageBitmap(rotated);
所以图像被旋转,代码没有大小变化。
按钮点击旋转:
                btn1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (rotate == -90)
                        {
                          //rotate back to original direction
                            old_rotate = -rotate;
                            matrix.postRotate(old_rotate);
                          //next rotation
                            random = randomize.nextInt(8) + 1;
                            rotate = getAngle(random);
                            matrix.postRotate(rotate);
                            rotatedBitmap = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(), myImg.getHeight(), matrix, true);
                            iv.setLayoutParams(new LinearLayout.LayoutParams(size, size));
                            iv.setImageBitmap(rotated);
                        }
                    }
                    });
当我启动活动时,图像以其原始大小出现,有时更小。当我单击一个按钮时,图像会变小或变大到其原始尺寸。
到底是怎么回事?