2016-04-01 22 views
0

Dairenin etrafında dönüp dönemiyorum. İşte Android daire merkezden dönmüyor mu?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:gravity="center" 
    android:layout_gravity="center" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="15.0dip" 

    <FrameLayout 
     android:padding="0.0dip" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="0.0dip"> 

     <ImageView 
      android:id="@+id/wheel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/wheel" /> 

     <ImageView 
      android:id="@+id/centre" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/centre" /> 

    </FrameLayout> 

</LinearLayout> 

ne olur bir görüntü var: Burada

benim xml olduğunu

screenshot

Resimdeki görebileceğiniz gibi, bir daire merkezi değildir ve kötü kokan merkezin etrafında dönün. Daire Ayrıca

ofscreen itti ve burada benim java alır:

Ben senin xml düşünüyorum
public class MainActivity 
    extends Activity 
    implements View.OnTouchListener { 
    private static final String TAG = "MainActivity"; 
    ImageView circleView; 
    double currentRotationDegrees; 
    double cx; 
    double cy; 
    float mPreviousX; 
    float mPreviousY; 
    private Matrix rotationMatrix; 

    public void onCreate(Bundle bundle) { 
     super.onCreate(bundle); 
     this.setContentView(R.layout.activity_main); 
     this.circleView = (ImageView)this.findViewById(R.id.wheel); 
     this.circleView.setOnTouchListener((View.OnTouchListener) this); 
     this.circleView.setScaleType(ImageView.ScaleType.MATRIX); 
     if (this.rotationMatrix == null) { 
     this.rotationMatrix = new Matrix(); 
     } 
     this.rotationMatrix.reset(); 
     this.currentRotationDegrees = 0.0; 
    } 

/* 
* Enabled aggressive block sorting 
*/ 
    public boolean onTouch(View view, MotionEvent motionEvent) { 
     this.cx = (double)this.circleView.getWidth()/2.0; 
     this.cy = (double)this.circleView.getHeight()/2.0; 
     float f = motionEvent.getX(); 
     float f2 = motionEvent.getY(); 

     Log.d((String)"MainActivity", (String)("Got x: " + f + " and y: " + f2)); 
     switch (motionEvent.getAction()) { 

      case 1: { 
       Log.d((String)"MainActivity", (String)("Current rotation degrees = " + this.currentRotationDegrees)); 
       double d = this.currentRotationDegrees % 30.0; 
       Log.d((String)"MainActivity", (String)("Rotation modulus = " + d)); 
       if (d == 0.0) break; 
       double d5 = d < 15.0 ? -1.0 * d : 30.0 - d; 
       this.rotationMatrix.postRotate((float)d5, (float)this.cx, (float)this.cy); 
       this.circleView.setImageMatrix(this.rotationMatrix); 
       this.currentRotationDegrees -= d; 
      } 

      case 2: { 
       Log.d((String)"MainActivity", (String)"Calculating rotation.."); 
       double d = (double)f - this.cx; 
       double d2 = Math.atan2((double)f2 - this.cy, d); 
       double d3 = (double)this.mPreviousX - this.cx; 
       double d4 = Math.toDegrees(d2 - Math.atan2((double)this.mPreviousY - this.cy, d3)); 
       Log.d((String)"MainActivity", (String)("Rotation degrees: " + d4)); 
       this.rotationMatrix.postRotate((float) d4, (float) this.cx, (float) this.cy); 
       this.circleView.setImageMatrix(this.rotationMatrix); 
       this.currentRotationDegrees = d4 + this.currentRotationDegrees; 
      } 
      default: { 
       break; 
      } 

     } 

     this.mPreviousX = f; 
     this.mPreviousY = f2; 
     return true; 
    } 
} 

cevap

0

.

 android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="0.0dip"> 

     <ImageView 
      android:id="@+id/image_camelot_wheel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:src="@drawable/wheel" /> 

     <ImageView 
      android:id="@+id/image_camelot_arrows" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:src="@drawable/centre" /> 
0

, LinearLayout dışında çevrenizde olduğunu ve LinearLayout en layout_margin ayarlayın. Çemberi merkez etrafında döndürmek istiyorsanız, LinearLayout.s genişliğini ve kenar boşluğunu almalı ve 2'ye bölünmüş olmalısınız. Bu kodu, bu kodla değiştirin.

+0

Cevabınızı daha net hale getirmek için lütfen kodu sağlarım? –