画像は大きいのですが、その一部だけを画面に表示する必要があります。私はこれをしました。私の問題は、画像を指で回転させる必要があることです。以下のコードは、小さな画像で正常に機能します。しかし、私の画像では、画像を上下に再配置し、奇妙に回転させるという間違った動作をしています。画像を正常に回転させるにはどうすればよいですか?, 小さな画像として. それから私は色に触れることができなければなりません。ここで答えが得られますが、まだ取り組まなければなりません。しかし、最初に、回転の問題をどのように解決できるか教えてください.2番目の問題についてアイデアがあれば、色に触れたいと思います.
これは画像です:
画面には次のように表示されます。
XML レイアウト:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView android:id="@+id/imag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/roata"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-200dp"
android:scaleType="center"/>
</RelativeLayout>
Java コード:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
picture = (ImageView)findViewById(R.id.imag);
picture.setOnTouchListener(onTableTouched);
}
public android.view.View.OnTouchListener onTableTouched = new android.view.View.OnTouchListener()
{
public boolean onTouch(View v, MotionEvent evt)
{
double r = Math.atan2(evt.getX() - picture.getWidth() / 2, picture.getHeight() / 2 - evt.getY());
int rotation = (int) Math.toDegrees(r);
if (evt.getAction() == MotionEvent.ACTION_DOWN)
{
//
}
if (evt.getAction() == MotionEvent.ACTION_MOVE)
{
updateRotation(rotation);
}
if (evt.getAction() == MotionEvent.ACTION_UP)
{
//
}
return true;
}
};
private void updateRotation(double rot)
{
float newRot = new Float(rot);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.roata);
Matrix matrix = new Matrix();
matrix.postRotate(newRot - 50);
Bitmap redrawnBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
picture.setImageBitmap(redrawnBitmap);
}
更新:
私はどこにもBitmap
行けなかったので、できるだけ似たものを得るMatrix
ために調整しようとしました. RotateAnimtaion()
2 番目のパラメーターとアニメーション ダイナミクスの期間を変更すると、Y 位置を変更せずに同様の結果を得ることができると思います。さて、問題は画像がトリミングされていることですscaleType="center"
. コードとスクリーンショットを投稿します。これは改善できますか?
Animation a = new RotateAnimation(0.0f, param,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
a.setFillEnabled(true);
a.setFillAfter(true);
a.setDuration(param);
picture.startAnimation(a);