我不得不在旋轉屏幕上的指尖時旋轉疊加圖像,順時針和逆時針旋轉,不想旋轉特定的天使。如果任何機構有解決方案,請幫助我。如何在android中(在指尖旋轉)順時針和逆時針旋轉圖像?
回答
檢查這個答案也許可以幫助你:How can i use RotateAnimation to rotate a circle?
非常感謝Dude ...它工作得很好。但我需要旋轉多個手指(大多數是兩個)的觸摸除了一個圖像。它用1個手指工作正常,但當我用2個手指使用它的前一個位置改變了一個眨眼。那麼你能幫我找到解決這個問題的方法嗎?提前致謝。 – Tapesh 2013-05-07 13:59:50
試試下面的鏈接,並檢查this鏈接之前也嘗試: -
public void Rotate(View v)
{
ImageView img = (ImageView)findViewById(R.id.imageView01);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.bharath);
// Getting width & height of the given image.
int w = bmp.getWidth();
int h = bmp.getHeight();
// Setting pre rotate to 90
Matrix mtx = new Matrix();
mtx.preRotate(90);
// Rotating Bitmap
Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);
img.setImageBitmap(rotatedBMP);
}
試試這個
AndroidBitmap.java
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.Spinner;
public class AndroidBitmap extends Activity {
//private final String imageInSD = "/sdcard/er.PNG";
ImageView myImageView;
Spinner spinnerScale;
SeekBar seekbarRotate;
private static final String[] strScale
= {"0.2x", "0.5x", "1.0x", "2.0x", "5.0x"};
private static final Float[] floatScale
= {0.2F, 0.5F, 1F, 2F, 5F};
private final int defaultSpinnerScaleSelection = 2;
private ArrayAdapter<String> adapterScale;
private float curScale = 1F;
private float curRotate = 0F;
Bitmap bitmap;
int bmpWidth, bmpHeight;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myImageView = (ImageView)findViewById(R.id.imageview);
spinnerScale = (Spinner)findViewById(R.id.scale);
seekbarRotate = (SeekBar)findViewById(R.id.rotate);
adapterScale = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, strScale);
adapterScale.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerScale.setAdapter(adapterScale);
spinnerScale.setSelection(defaultSpinnerScaleSelection);
curScale = floatScale[defaultSpinnerScaleSelection];
BitmapDrawable img = (BitmapDrawable) getResources()
.getDrawable(R.drawable.ic_launcher);
bitmap = img.getBitmap();//BitmapFactory.decodeFile(imageInSD);
bmpWidth = bitmap.getWidth();
bmpHeight = bitmap.getHeight();
drawMatrix();
spinnerScale.setOnItemSelectedListener(spinnerScaleOnItemSelectedListener);
seekbarRotate.setOnSeekBarChangeListener(seekbarRotateSeekBarChangeListener);
}
private void drawMatrix(){
Matrix matrix = new Matrix();
matrix.postScale(curScale, curScale);
matrix.postRotate(curRotate);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bmpWidth, bmpHeight, matrix, true);
myImageView.setImageBitmap(resizedBitmap);
}
private SeekBar.OnSeekBarChangeListener seekbarRotateSeekBarChangeListener
= new SeekBar.OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
curRotate = (float)progress;
drawMatrix();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}};
private Spinner.OnItemSelectedListener spinnerScaleOnItemSelectedListener
= new Spinner.OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
curScale = floatScale[arg2];
drawMatrix();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
spinnerScale.setSelection(defaultSpinnerScaleSelection);
curScale = floatScale[defaultSpinnerScaleSelection];
}};
}
佈局文件
的main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello, Android image rotate"
/>
<Spinner
android:id="@+id/scale"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<SeekBar
android:id="@+id/rotate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5px"
android:max="360"
android:progress="0"
/>
<ImageView
android:id="@+id/imageview"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
/>
</LinearLayout>
希望這有助於
手指觸摸嗯!你爲什麼沒有說過。 [查看此鏈接](http://stackoverflow.com/a/2939405/2345913)。在這裏,你可以獲得手指觸摸位置的座標,捕捉運動,然後使用上述邏輯,我希望這可以解決這個問題。 – CRUSADER 2013-05-07 12:18:39
- 1. 如何在android中順時針和逆時針旋轉圖像?
- 2. 順時針/逆時針旋轉圖像
- 3. 順時針和逆時針方向旋轉圖像
- 4. 如何在jQuery中滾動/順時針和逆時針旋轉圖像?
- 5. JQuery-順時針旋轉div並逆時針旋轉
- 6. Javascript旋轉 - 如何逆時針旋轉?
- 7. jQuery:以90度增量順時針/逆時針旋轉圖像?
- 8. 如何順時針和逆時針旋轉圓圈?
- 9. 使用c中的平移變換順時針和逆時針旋轉圖像#
- 10. 在android中順時針和逆時針方向旋轉一個正方形
- 11. 帶8弧的圓弧svg順時針和逆時針旋轉
- 12. 如何順時針或逆時針旋轉圖像,以較短者爲準?
- 13. 使用javascript在div內順時針或逆時針旋轉圖像
- 14. 使用LibGDX順時針旋轉圖像
- 15. 順時針旋轉90度的圖像
- 16. 如何在逆時針旋轉後重建圖像
- 17. Flash CS4:順時針或逆時針旋轉對象
- 18. 查找QDial是否順時針或逆時針旋轉
- 19. 順時針旋轉線
- 20. 旋轉陣列順時針
- 21. 旋轉陣列順時針
- 22. 如何順時針旋轉90度(swift3)
- 23. 如何順時針旋轉對象?
- 24. Java逆時針旋轉90度
- 25. Excel旋轉(不轉置)表順時針旋轉90度
- 26. 如何在android中執行順時針和逆時針手勢
- 27. 旋轉SVG元素順時針
- 28. 順時針旋轉2d向量90度
- 29. 順時針方向旋轉2d形狀
- 30. 順時針旋轉鏈接列表
什麼是 「形象」?什麼是「疊加」? – CommonsWare 2013-05-07 11:21:38
你是指動畫,還是旋轉源圖像本身? – kabuto178 2013-05-07 11:23:54
你可以更多地解釋一下,或者添加你已經擁有的代碼段將有助於更多的 – Triode 2013-05-07 11:24:01