2016-12-09 1 views
0

Hier ist das Android Studio-Code für meinen Android-App:Ich möchte den Rand mit Animation ändern, um dies in meiner Android App zu verschieben. Wie es geht?

FrameLayout root = (FrameLayout) findViewById(R.id.root); 
    ImageView img = new ImageView(this); 
    img.setBackgroundColor(Color.RED); 
    //..load something inside the ImageView, we just set the background color 

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(20, 20); 
    params.leftMargin=Math.round(deltaX); 
    params.topMargin=Math.round(deltaY); 
    root.addView(img,params); 
    //... 

Ich möchte dies mit Animation bewegen, wenn der Wert von topmargin und leftmargin ändern.

Antwort

0

können Sie auf Padding

FrameLayout root = (FrameLayout) findViewById(R.id.root); 
    ImageView img = new ImageView(this); 
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(20, 20); 
    img.setLayoutParams(params); 
    img.setBackgroundColor(Color.RED); 
    //..load something inside the ImageView, we just set the background color 

    root.setPadding(deltaX, deltaX, 0, 0); 
    root.addView(img); 

Dann ändern Sie Property Animation

ObjectAnimator.ofFloat(root, "translationX", 0, 1000).start(); 
    ObjectAnimator.ofFloat(root, "translationY", 0, 1000).start(); 

oder

root.animate().translationY(100); 
+0

Sie Sie Antwort mir danken .. hilft viel nutzen können. Kannst du mir bitte sagen, wie man die Animation glatt macht? Ich denke, es kann mit den für Animation erstellten Klassen gemacht werden. –

+0

@FaruqueAhamedMollick Aktualisiert. – Yat3s

Verwandte Themen