ImageView とボタンがあるという要件があります。
http://i1289.photobucket.com/albums/b509/salikclub/Rotate-Last-Start_zps0d2fced8.png
ボタンをクリックしたときに画像を回転させたい。フルスクリーンの画像が必要です。ボタンの画像をクリックすると回転しますが、全画面表示にはなりません。以下のリンクをご覧ください。
http://i1289.photobucket.com/albums/b509/salikclub/Rotate-Last1_zps2ccb1326.png
その後もボタン画像をクリックすると回転します。しかし、位置が変更され、全画面表示されません。
私の要件は、ボタンをクリックすると画像が時計回りに回転し、フルスクリーンで表示されることです。もう一度クリックすると、ボタンの画像が時計回りに回転し、フルスクリーンで表示される必要があります。同様に、ボタン画像をクリックすると回転する必要があります。
したがって、誰かが私を助けることができますか? サンプルコードまたはリンクを教えていただければ、非常に高く評価されます。
ここに私が試しているコードがあります、
main.xml
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<ImageView
android:id="@+id/imgView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:scaleType="fitXY"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:src="@drawable/matterhorn"
/>
<Button
android:id="@+id/btnRotate"
android:layout_width="65dp"
android:layout_height="35dp"
android:layout_gravity="bottom|left"
android:layout_marginLeft="190dp"
android:layout_marginBottom="15dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableLeft="@drawable/btn_icon_rotate"
>
</Button>
</merge>
これは私のメイン アクティビティ「MainActivity.java」です。
package com.imageview.rotate;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Matrix;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
public class MainActivity extends Activity implements OnClickListener{
private Button btnRotate;
private ImageView imgview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imgview = (ImageView) findViewById(R.id.imgView);
btnRotate = (Button) findViewById(R.id.btnRotate);
btnRotate.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnRotate:
Matrix matrix=new Matrix();
imgview.setScaleType(ScaleType.MATRIX); //required
matrix.postRotate((float) 180f, imgview.getDrawable().getBounds().width()/2, imgview.getDrawable().getBounds().height()/2);
imgview.setImageMatrix(matrix);
break;
}
}
}
前もって感謝します。