Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:通过旋转ImageView,它可以获得双倍的效果_Android_Xml - Fatal编程技术网

Android:通过旋转ImageView,它可以获得双倍的效果

Android:通过旋转ImageView,它可以获得双倍的效果,android,xml,Android,Xml,我正在制作一个简单的国际象棋应用程序,为了方便用户,我需要旋转一个imageView,当我使用这个方法时,我的pawn的imageView变大了 ImageView pawn; pawn = (ImageView) findViewById (R.id.pawn); pawn.setScaleType(ScaleType.MATRIX); Matrix rotationMatrix = new Matrix(); rotationMatrix.postRotate(180f, pawn.get

我正在制作一个简单的国际象棋应用程序,为了方便用户,我需要旋转一个imageView,当我使用这个方法时,我的pawn的imageView变大了

ImageView pawn;
pawn = (ImageView) findViewById (R.id.pawn);

pawn.setScaleType(ScaleType.MATRIX);
Matrix rotationMatrix = new Matrix();
rotationMatrix.postRotate(180f, pawn.getDrawable().getBounds().width()/2,
     pawn.getDrawable().getBounds().height()/2);
pawn.setImageMatrix(rotationMatrix);

我还试着将角度设置为“0f”而不是“180f”,我只能看到左上角图像的1/4,我认为这与ScaleType.MATRIX或其他东西有关,我被困住了。救救我

实际上我正在使用一个新函数myRotate(),但它们仍然存在一个问题,即您只能在main函数中使用“getResources()”,因为它不是静态的

public void rotate(ImageView im, int id, int degree){
    Bitmap bMap;
    Matrix matrix;
    //Decode Image using Bitmap factory.
    bMap = BitmapFactory.decodeResource(getResources(), id);
    //Create object of new Matrix.
    matrix = new Matrix();

    //set image rotation value to "degree" degrees in matrix.
    matrix.postRotate(degree);

    //Create bitmap with new values.
    Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0,
            bMap.getWidth(), bMap.getHeight(), matrix, true);

    //put rotated image in ImageView.
    im.setImageBitmap(bMapRotate);
}