here (터치/플링에서 이미지를 동적으로 회전시키는) 튜토리얼을 가져 와서 하나의 이미지 대신 전체 레이아웃으로 리팩터링하려고했습니다. 그래서 나는 지금처럼 TutorialActivity에서 rotateDialer() 메소드를 변경했습니다 :레이아웃을 안드로이드로 회전하려고 시도합니다. 캔버스가 회전하지 않습니다.
걸기 내가 그러나 많은 도로가에서 설정 한 캔버스를 회전 재정의 된 onDraw() 메소드를 생성 한 사용자 정의 레이아웃입니다private void rotateDialer(float degrees) {
//matrix.postRotate(degrees, dialerWidth/2, dialerHeight/2);
//dialer.setImageMatrix(matrix);
dialer.setNextRotation(degrees, dialerWidth/2, dialerHeight/2);
dialer.invalidate();
info.setText("Current Quadrant Touched = "+currentQuadrantTouched
+"\nAngle = "+degrees);
}
setNextRotation() 메서드를 사용하지만 캔버스가 회전하는 것처럼 보이지 않습니다!
<ImageView
android:id="@+id/topLeftImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="38dp"
android:clickable="true"
android:layout_marginTop="28dp"
android:src="@drawable/icon" />
<ImageView
android:id="@+id/topRightImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:clickable="true"
android:layout_alignParentRight="true"
android:layout_marginRight="50dp"
android:src="@drawable/icon" />
<ImageView
android:id="@+id/bottomLeftImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:clickable="true"
android:layout_marginBottom="24dp"
android:layout_marginLeft="22dp"
android:src="@drawable/icon" />
<ImageView
android:id="@+id/bottomRightImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:clickable="true"
android:layout_alignParentRight="true"
android:layout_marginRight="28dp"
android:src="@drawable/icon" />
</RelativeLayout>
왜 캔버스가 눈에 띄게 회전하지 않습니다
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
public class DialView extends FrameLayout {
public static final String LOG_TAG = "DialView";
RelativeLayout dialView;
float degrees;
float px;
float py;
public DialView(Context context) {
super(context);
init();
// TODO Auto-generated constructor stub
}
public DialView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
// TODO Auto-generated constructor stub
}
public DialView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
init();
}
private void init()
{
//initialise rotation
this.degrees = 0;
this.px = 0;
this.py = 0;
LayoutInflater inflator = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
dialView = (RelativeLayout) inflator.inflate(R.layout.dial_view, this,false);
addView(dialView);
Log.d(LOG_TAG, "DialView: init() "+ degrees+"degrees around ("+getWidth()/2+","+getHeight()/2+")");
}
public void setNextRotation(float degrees, float px, float py)
{
this.degrees = degrees;
this.px = px;
this.py = py;
Log.d(LOG_TAG, "Next Rotation = "+ degrees+"degrees around ("+px+","+py+")");
}
@Override
protected void onDraw(Canvas canvas) {
canvas.save();
// canvas.rotate(45,<appropriate x pivot value>,<appropriate y pivot value>);
canvas.rotate(degrees, px, py);
Log.d(LOG_TAG, "onDraw: Rotation = "+ degrees+"degrees around ("+px+","+py+")");
super.onDraw(canvas);
canvas.restore();
}
}
이는 dial_view.xml는 : 여기 내 사용자 지정 레이아웃은? 각도 계산 후에 onTouch() 다이얼러가 무효화되어 계산이 올바르게 작동하지만 (보기에 로그에서 값이 변경됨) 뷰가 회전하지 않는 것 같습니다. 잘못된?
나는 이것이 오래된 게시물이라는 것을 알고 있지만 이것을 이해하는 데 단지 2 시간을 소비한다. 위는 canvas.save()를 움직이면 작동 할 것이다. before canvas.rotate (degrees, px, py); – Warpzit