我有一個LinearLayout與ImageView與中心的正方形圖像,我需要應用旋轉。將ImageView的四邊連接起來是一個由4個其他視圖構成的框架。如果我旋轉ImageView 45degrees,ImageView是否會被其他視圖剪切? rotateAnimation如何尊重ImageView的邊界?旋轉正方形與旋轉動畫
0
A
回答
0
我認爲這會回答你的問題:
注:不管如何動畫可以移動或調整大小,保存你的動畫不會自動調整,以適應它的視圖的邊界。即便如此,動畫仍然會超出其視圖範圍,並且不會被剪輯。但是,如果動畫超出了父視圖的邊界,剪切就會發生。
(Source)
1
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
public class ImageFunctionsActivity extends Activity
{
/** Called when the activity is first created. */
ImageView iv;
float degree=0;
GestureDetector gd;
Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
iv=(ImageView) findViewById(R.id.imageTeddy);
context=getApplicationContext();
rotate(degree);
}
void rotate(float x)
{
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.tedd);
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
int newWidth = 200;
int newHeight = 200;
// calculate the scale - in this case = 0.4f
float scaleWidth = ((float) newWidth)/width;
float scaleHeight = ((float) newHeight)/height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
matrix.postRotate(x);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,width, height, matrix, true);
iv.setScaleType(ScaleType.CENTER);
iv.setImageBitmap(resizedBitmap);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode==KeyEvent.KEYCODE_DPAD_UP)
{
degree=degree+10;
rotate(degree);
}
if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) // rotate anti-clockwise
{
degree=degree-10;
rotate(degree);
}
return true;
}
}
+0
這個代碼來旋轉圖像,你按UP或DOWN鍵... – MAC 2012-04-06 10:20:53
相關問題
- 1. 畫正方形並旋轉它?
- 2. 旋轉動畫
- 3. 旋轉動畫
- 4. Webgl drawelements旋轉正方形
- 5. Angular2動畫旋轉方向?
- 6. Android啓動畫面旋轉或旋轉
- 7. Android旋轉動畫
- 8. CSS3旋轉動畫
- 9. CSS旋轉動畫
- 10. Android旋轉動畫
- 11. ThreeJS旋轉動畫
- 12. 動畫旋轉軸
- 13. NSImageCell旋轉動畫
- 14. 動畫旋轉PathGeometry
- 15. Android旋轉動畫
- 16. WPF旋轉動畫
- 17. 旋轉圖像。動畫列表還是動畫旋轉? (Android)
- 18. 旋轉畫布
- 19. 用畫布上的旋轉矩陣旋轉等邊三角形
- 20. 旋轉正方形函數JS Canvas
- 21. 旋轉圖形
- 22. 旋轉矩形?
- 23. jQuery的動畫旋轉格
- 24. Qt即時旋轉動畫
- 25. 旋轉動畫的Android 4.0
- 26. WPF 3d旋轉動畫
- 27. HTML5旋轉/動畫背景
- 28. 圖像旋轉動畫
- 29. 動畫旋轉的UIImageView
- 30. 動畫旋轉的Android
爲什麼不嘗試一下,看看會發生什麼? – 2012-01-10 18:35:57