2016-04-14 5 views
0

Ich habe eine App, die eine Kamera verwendet,Taste Flip-Animation hinzufügen - Android

Es gibt es eine Option, die Kamera umschalten können, Wenn diese Schaltfläche Ich möchte den Knopf drehen und für sie angeklickt wird in den ursprünglichen Zustand zurückzukehren, ich kann nicht scheinen, eine Lösung zu finden oder eine Möglichkeit, dies zu tun.

Irgendwelche Vorschläge?

+0

einige Code anzeigen und präziser sein. Was hast du bisher versucht? –

Antwort

0

Attribute der Skala in ImageView

Wenn diese Schaltfläche geklickt wird, wenn Sie auf den Knopf drehen wollen und für sie in den ursprünglichen Zustand zurück

android:scaleX="-1" //To flip horizontally 
android:scaleY="-1" //To flip vertically 

Und umgekehrt

Beispiel:

float scalingFactor = 0.5f; // scale down to half the size 
view.setScaleX(scalingFactor); 
view.setScaleY(scalingFactor); 
+0

hilft dir diese Antwort nicht? @ 2D3D –

0

Beispiel existiert bei And roid Entwicklerleitfäden:
https://developer.android.com/training/animation/cardflip.html
https://developer.android.com/training/animation/anim_card_flip.mp4

Für die Verwendung Animation zur Einzelansicht (nicht alle Bildschirm) verwenden View.setAnimation()

Animation a = AnimationUtils.loadAnimation(this,R.anim.card_flip_left_in); 
myView.setAnimation(a); 
a.startNow(); 

erstellen Animation xmls:

card_flip_left_in.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <!-- Before rotating, immediately set the alpha to 0. --> 
    <objectAnimator 
     android:valueFrom="1.0" 
     android:valueTo="0.0" 
     android:propertyName="alpha" 
     android:duration="0" /> 

    <!-- Rotate. --> 
    <objectAnimator 
     android:valueFrom="-180" 
     android:valueTo="0" 
     android:propertyName="rotationY" 
     android:interpolator="@android:interpolator/accelerate_decelerate" 
     android:duration="@integer/card_flip_time_full" /> 

    <!-- Half-way through the rotation (see startOffset), set the alpha to 1. --> 
    <objectAnimator 
     android:valueFrom="0.0" 
     android:valueTo="1.0" 
     android:propertyName="alpha" 
     android:startOffset="@integer/card_flip_time_half" 
     android:duration="1" /> 
</set> 

card_flip_left_out.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <!-- Rotate. --> 
    <objectAnimator 
     android:valueFrom="0" 
     android:valueTo="180" 
     android:propertyName="rotationY" 
     android:interpolator="@android:interpolator/accelerate_decelerate" 
     android:duration="@integer/card_flip_time_full" /> 

    <!-- Half-way through the rotation (see startOffset), set the alpha to 0. --> 
    <objectAnimator 
     android:valueFrom="1.0" 
     android:valueTo="0.0" 
     android:propertyName="alpha" 
     android:startOffset="@integer/card_flip_time_half" 
     android:duration="1" /> 
</set> 

card_flip_right_in.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <!-- Before rotating, immediately set the alpha to 0. --> 
    <objectAnimator 
     android:valueFrom="1.0" 
     android:valueTo="0.0" 
     android:propertyName="alpha" 
     android:duration="0" /> 

    <!-- Rotate. --> 
    <objectAnimator 
     android:valueFrom="180" 
     android:valueTo="0" 
     android:propertyName="rotationY" 
     android:interpolator="@android:interpolator/accelerate_decelerate" 
     android:duration="@integer/card_flip_time_full" /> 

    <!-- Half-way through the rotation (see startOffset), set the alpha to 1. --> 
    <objectAnimator 
     android:valueFrom="0.0" 
     android:valueTo="1.0" 
     android:propertyName="alpha" 
     android:startOffset="@integer/card_flip_time_half" 
     android:duration="1" /> 
</set> 

card_flip_right_out.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <!-- Rotate. --> 
    <objectAnimator 
     android:valueFrom="0" 
     android:valueTo="-180" 
     android:propertyName="rotationY" 
     android:interpolator="@android:interpolator/accelerate_decelerate" 
     android:duration="@integer/card_flip_time_full" /> 

    <!-- Half-way through the rotation (see startOffset), set the alpha to 0. --> 
    <objectAnimator 
     android:valueFrom="1.0" 
     android:valueTo="0.0" 
     android:propertyName="alpha" 
     android:startOffset="@integer/card_flip_time_half" 
     android:duration="1" /> 
</set> 
+0

Sie haben nicht verstanden, was ich erreichen möchte, nur die Schaltfläche wird nicht den gesamten Bildschirm spiegeln – 2D3D

+0

Es ist nicht notwendig. Verwenden Sie diese Animationen für die Einzelansicht Animation a = AnimationUtils.loadAnimation (diese, R.anim.card_flip_left_in); myView.setAnimation (a); a.startNow(); –

0

Verwenden ObjectAnimator wie folgt aus:

cameraSwitchButton.setImageResource(icon1ResourceId); 

    cameraSwitchButton.setOnClickListener({       
      ObjectAnimator animator = ObjectAnimator.ofFloat(cameraSwitchButton, "scaleX", 0.0f).setDuration(100); 
      animator.addListener(new AnimatorListenerAdapter() { 
       @Override 
       public void onAnimationEnd(Animator animator) { 
        cameraSwitchButton.setImageResource(icon2ResourceId); 
        ObjectAnimator.ofFloat(cameraSwitchButton, "scaleX", 1.0f).setDuration(100).start(); 
       } 
      }); 
      animator.start(); 

      // Camera switch logic here... 
    }); 

Wenn Sie es wollen zurück kippen, entscheiden, die Sie an diesen Linien müssen Icon:

cameraSwitchButton.setImageResource(icon(1 or 2)ResourceId);