larsa توسعه دهنده تازه وارد سپاس ها 10 سپاس شده 1 بار در 1 ارسال
| حرکت چند کامپوننت در یک دایره - دیروز, 11:47 PM
من ی صفحه اکتیویتی دارم که میخوام تمام ویجت هام دور یک نیم دایره بچرخن و بعد در جایی که چرخش تموم میشه بمونن ویجت ها به صورت نیم دایره دور نیم دایره ثابت قرار بگیرننیم دایره رو ایجاد کردم و یکی از ویجت ها هم به همون شکلی که نیاز دارم در برنامه قرار میگیرهاین کلاس انیمیشنم هستpublic class MyAnimation extends Animation { private List<View> 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> 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<View> 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<View>(); views.add(ProductButton); views.add(AboutButton); for (int i=1; views.size()<4;i++) { Animation anim = new MyAnimation((List<View> 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"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 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">
<ImageButton 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"
/>
<ImageView 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.support.design.widget.FloatingActionButton 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.support.design.widget.FloatingActionButton 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" />
</RelativeLayout> برنامه ام روی حلقه خطا دارهممنون میشم بهم بگید باید چیکار کنم که هر دوی Buttonهام روی انیمیشن حرکت کنند |
|
| |
روید باکس...
ما را در سایت روید باکس دنبال می کنید
برچسب : نویسنده : کاوه محمدزادگان roid بازدید : 176 تاريخ : چهارشنبه 3 شهريور 1395 ساعت: 2:39