Skip to content

Instantly share code, notes, and snippets.

@talhahasanzia
Created June 13, 2016 06:56
Show Gist options
  • Save talhahasanzia/bf02a3ceadc8dd895aba865acc652aad to your computer and use it in GitHub Desktop.
Save talhahasanzia/bf02a3ceadc8dd895aba865acc652aad to your computer and use it in GitHub Desktop.
Android Pop-Up Animation
public class MainActivity extends AppCompatActivity {
boolean isPopped=false;
double h;
double w;
LinearLayout popUpFrame;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView popUpText=(TextView)findViewById(R.id.textView4);
popUpFrame=(LinearLayout) findViewById(R.id.popUpContainer);
popUpFrame.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final LinearLayout fm = (LinearLayout) v;
Animation expandIn = AnimationUtils.loadAnimation(MainActivity.this, R.anim.pop_up);
if(isPopped)
{
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) fm.getLayoutParams();
params.height = (int) h;
params.width = (int) w;
fm.setLayoutParams(params);
isPopped=false;
}
else {
popUpFrame.startAnimation(expandIn);
isPopped=true;
}
expandIn.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) fm.getLayoutParams();
double height= h*1.8;
double width=w*1.8;
params.height = (int)(height);
params.width = (int) (width);
fm.setLayoutParams(params);
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
;
}
});
}
@Override
protected void onResume() {
super.onResume();
h=popUpFrame.getLayoutParams().height;
w=popUpFrame.getLayoutParams().width;
}
}
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="1.25"
android:toYScale="1.2"
android:pivotX="50%"
android:pivotY="50%"
android:duration="400"/>
<scale
android:fromXScale="1.25"
android:fromYScale="1.2"
android:toXScale="1.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="1"
android:duration="300"/>
</set>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment