رفتن به مطلب
انجمن اندروید ایران | آموزش برنامه نویسی اندروید و موبایل
  • android.png.1fab383bc8500cd93127cebc65b1dcab.png

حرکت چند کامپوننت در یک دایره


پست های پیشنهاد شده

من ی صفحه اکتیویتی دارم که میخوام تمام ویجت هام دور یک نیم دایره بچرخن و بعد در جایی که چرخش تموم میشه بمونن ویجت ها به صورت نیم دایره دور نیم دایره ثابت قرار بگیرن

نیم دایره رو ایجاد کردم و یکی از ویجت ها هم به همون شکلی که نیاز دارم در برنامه قرار میگیره

این کلاس انیمیشنم هست

public class MyAnimation extends Animation {

private List view;

private float cx, cy; // center x,y position of circular path

private float prevX, prevY; // previous x,y position of image during animation

private float r; // radius of circle

private float prevDx, prevDy;

/**

* @param view - View that will be animated

* @param r - radius of circular path

*/

public MyAnimation(List view, float r){

this.view = view;

this.r = r;

}

@Override

public boolean willChangeBounds() {

return true;

}

@Override

public void initialize(int width, int height, int parentWidth, int parentHeight) {

cx=0;

cy=0;

// calculate position of image center

/* int cxImage = width / 2;

int cyImage = height / 2;

cx = view.getLeft() + cxImage;

cy = view.getTop() + cyImage;*/

// set previous position to center

prevX = cx;

prevY = cy;

}

@Override

protected void applyTransformation(float interpolatedTime, Transformation t) {

if(interpolatedTime == 0){

t.getMatrix().setTranslate(prevDx, prevDy);

return;

}

int a=330;

for (int i=1;i<3;i++)

{

float angleDeg = (interpolatedTime * a + 90) % 360;

float angleRad = (float) Math.toRadians(angleDeg);

// r = radius, cx and cy = center point, a = angle (radians)

float x = (float) (cx + r * Math.cos(angleRad));

float y = (float) (cy + r * Math.sin(angleRad));

float dx = prevX - x;

float dy = prevY - y;

prevX = x;

prevY = y;

prevDx = dx;

prevDy = dy;

t.getMatrix().setTranslate(dx,dy);

a=a-60;

}

}

}

 و اینم کلاس اکتیویتی

public class MainActivity extends AppCompatActivity {
List views;
FloatingActionButton ProductButton, AboutButton;
protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       ProductButton = (FloatingActionButton) findViewById(R.id.ProductButton);
       AboutButton = (FloatingActionButton) findViewById(R.id.AboutButton);
       views=new ArrayList();
       views.add(ProductButton);
       views.add(AboutButton);
       for (int i=1; views.size()<4;i++)
              {
                   Animation anim = new MyAnimation((List views.get(i), height * 2 / 5);
                   anim.setDuration(5000);
                   anim.setFillAfter(true);
                   views.get(i).startAnimation(anim);
               }
}
}

 و اخری هم xml

<?xml version="1.0" encoding="utf-8"?>

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

xmlns:app="http://schemas.android.com/apk/res-auto"

tools:context="com.example.hajar.floatactionbutton.MainActivity">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_marginRight="0dp"

android:background="#00FFFFFF"

android:layout_centerVertical="true"

android:layout_alignParentRight="true"

android:layout_alignParentEnd="false"

android:id="@+id/Semicircular"

/>

android:id="@+id/image"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@mipmap/ic_launcher"

android:layout_alignParentBottom="true"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true" />

android:id="@+id/ProductButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="bottom|end"

android:layout_centerVertical="true"

android:layout_alignParentRight="true"

android:layout_alignParentEnd="true" />

android:id="@+id/AboutButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="bottom|end"

android:layout_centerVertical="true"

android:layout_alignParentRight="true"

android:layout_alignParentEnd="true" />

برنامه ام روی حلقه خطا داره

ممنون میشم بهم بگید باید چیکار کنم که هر دوی Buttonهام روی انیمیشن حرکت کنند

لینک ارسال
به اشتراک گذاری در سایت های دیگر

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...