Skip to content

Instantly share code, notes, and snippets.

@maydin
Created September 28, 2016 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maydin/0b31c6370cb9c25a78cb64d20b9a6c4c to your computer and use it in GitHub Desktop.
Save maydin/0b31c6370cb9c25a78cb64d20b9a6c4c to your computer and use it in GitHub Desktop.
MainActivity
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
TextSwitcher myTextSwitcher;
AnimationSet as;
AppCompatButton button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myTextSwitcher = (TextSwitcher) this.findViewById(R.id.text_switcher);
button = (AppCompatButton) this.findViewById(R.id.button);
button.setOnClickListener(this);
myTextSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
AppCompatTextView textView = (AppCompatTextView) inflater.inflate(R.layout.textview, null);
return textView;
}
});
final Animation in = new AlphaAnimation(0.0f, 1.0f);
final Animation out = new AlphaAnimation(1.0f, 0.0f);
in.setDuration(100);
out.setDuration(100);
as = new AnimationSet(true);
as.addAnimation(out);
as.addAnimation(in);
}
@Override
public void onClick(View view) {
myTextSwitcher.setText("Bye World");
myTextSwitcher.startAnimation(as);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment