Last active
March 19, 2018 10:06
-
-
Save bluemyria/3095c2c5544358759e587907e9611887 to your computer and use it in GitHub Desktop.
Android - 017 - Animations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////////////////////////////// | |
// in der Activity | |
////////////////////////////////////////////////////////////////////////////////////////////// | |
public class MainActivity extends AppCompatActivity { | |
private Button btn; | |
private ImageView bild; | |
private Animation animEinklappen, animAusklappen; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
btn = findViewById(R.id.btn); | |
btn.setOnClickListener(new myOCL()); | |
bild = findViewById(R.id.bild); | |
animEinklappen = AnimationUtils.loadAnimation(this,R.anim.einklappen); | |
animAusklappen = AnimationUtils.loadAnimation(this,R.anim.ausklappen); | |
animEinklappen.setAnimationListener(new myAnimListener()); | |
} | |
private class myOCL implements View.OnClickListener { | |
@Override | |
public void onClick(View view) { | |
bild.startAnimation(animEinklappen); | |
btn.startAnimation(animEinklappen); | |
} | |
} | |
private class myAnimListener implements Animation.AnimationListener { | |
@Override | |
public void onAnimationStart(Animation animation) { | |
} | |
@Override | |
public void onAnimationEnd(Animation animation) { | |
if (animation == animEinklappen) { | |
bild.startAnimation(animAusklappen); | |
btn.startAnimation(animAusklappen); | |
} | |
} | |
@Override | |
public void onAnimationRepeat(Animation animation) { | |
} | |
} | |
} | |
////////////////////////////////////////////////////////////////////////////////////////////// | |
// in res/anim/ausklappen.xml | |
////////////////////////////////////////////////////////////////////////////////////////////// | |
<?xml version="1.0" encoding="utf-8"?> | |
<set xmlns:android="http://schemas.android.com/apk/res/android"> | |
<scale | |
android:pivotX="50%" | |
android:pivotY="50%" | |
android:duration="3000" | |
android:fromXScale="1.0" | |
android:fromYScale="0.0" | |
android:toXScale="1.0" | |
android:toYScale="1.0" /> | |
<alpha | |
android:fromAlpha="0.0" | |
android:toAlpha="1.0" | |
android:duration="3000" /> | |
</set> | |
////////////////////////////////////////////////////////////////////////////////////////////// | |
// in res/anim/einklappen.xml | |
////////////////////////////////////////////////////////////////////////////////////////////// | |
<?xml version="1.0" encoding="utf-8"?> | |
<set xmlns:android="http://schemas.android.com/apk/res/android"> | |
<scale | |
android:pivotX="50%" | |
android:pivotY="50%" | |
android:duration="6000" | |
android:fromXScale="1.0" | |
android:fromYScale="1.0" | |
android:toXScale="0.0" | |
android:toYScale="1.0" /> | |
<rotate | |
android:duration="3000" | |
android:pivotX="50%" | |
android:pivotY="50%" | |
android:fromDegrees="0" | |
android:toDegrees="-360" | |
android:startOffset="1500" | |
/> | |
</set> | |
////////////////////////////////////////////////////////////////////////////////////////////// | |
// in res/layout/main_activity.xml | |
////////////////////////////////////////////////////////////////////////////////////////////// | |
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="...........w3t2_animationen_mariab.MainActivity"> | |
<ImageView | |
android:id="@+id/bild" | |
android:layout_width="274dp" | |
android:layout_height="223dp" | |
android:layout_marginEnd="8dp" | |
android:layout_marginStart="8dp" | |
android:layout_marginTop="184dp" | |
android:scaleType="fitCenter" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
app:srcCompat="@drawable/ellas" /> | |
<Button | |
android:id="@+id/btn" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Start Animation" /> | |
</android.support.constraint.ConstraintLayout> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment