下面列出了android.widget.TextSwitcher#setOutAnimation ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initializeTextSwitcher(@NonNull final Context context) {
selectedTextView = new TextSwitcher(getContext());
selectedTextView.setFactory(this);
selectedTextView.setAnimateFirstView(false);
selectedTextView.setBackgroundResource(mSelectedTextBackground);
if (mTextSwitcherInAnimation != 0) {
selectedTextView.setInAnimation(context, mTextSwitcherInAnimation);
}
if (mTextSwitcherOutAnimation != 0) {
selectedTextView.setOutAnimation(context, mTextSwitcherOutAnimation);
}
LayoutParams params = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
params.gravity = Gravity.CENTER;
selectedTextView.setLayoutParams(params);
selectedTextView.setLayerType(LAYER_TYPE_HARDWARE, null);
addView(selectedTextView);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.text_switcher_1);
mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this);
Animation in = AnimationUtils.loadAnimation(this,
android.R.anim.fade_in);
Animation out = AnimationUtils.loadAnimation(this,
android.R.anim.fade_out);
mSwitcher.setInAnimation(in);
mSwitcher.setOutAnimation(out);
Button nextButton = (Button) findViewById(R.id.next);
nextButton.setOnClickListener(this);
updateCounter();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTextSwitcher = (TextSwitcher) findViewById(R.id.textSwitcher);
mTextSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
TextView textView = new TextView(MainActivity.this);
textView.setTextSize(18);
textView.setGravity(Gravity.CENTER);
return textView;
}
});
mTextSwitcher.setInAnimation(this, android.R.anim.fade_in);
mTextSwitcher.setOutAnimation(this, android.R.anim.fade_out);
mImageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher);
mImageSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
ImageView imageView = new ImageView(MainActivity.this);
return imageView;
}
});
mImageSwitcher.setInAnimation(this, android.R.anim.slide_in_left);
mImageSwitcher.setOutAnimation(this, android.R.anim.slide_out_right);
onSwitch(null);
}
@SuppressLint("PrivateResource")
@Override
protected void onCreate(Bundle savedInstanceState) {
switch (Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "0"))) {
case ActivityMain.THEME_LIGHT : setTheme(R.style.AppThemeLight); break;
case ActivityMain.THEME_DARK : setTheme(R.style.AppThemeDark); break;
default: setTheme(R.style.AppThemeLight); break;
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
mReplaceFragmentStrategy = new PreferenceScreenNavigationStrategy.ReplaceFragment(this, R.anim.abc_fade_in, R.anim.abc_fade_out, R.anim.abc_fade_in, R.anim.abc_fade_out);
if (savedInstanceState == null) {
mSettingsFragment = FragmentSettings.newInstance(null);
getSupportFragmentManager().beginTransaction().add(R.id.content, mSettingsFragment, "Settings").commit();
} else {
mSettingsFragment = (FragmentSettings) getSupportFragmentManager().findFragmentByTag("Settings");
}
getSupportFragmentManager().addOnBackStackChangedListener(this);
mToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setDisplayHomeAsUpEnabled(true);
}
// Cross-fading title setup.
mTitle = getTitle();
mTitleSwitcher = new TextSwitcher(mToolbar.getContext());
mTitleSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
TextView tv = new AppCompatTextView(mToolbar.getContext());
TextViewCompat.setTextAppearance(tv, R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);
return tv;
}
});
mTitleSwitcher.setCurrentText(mTitle);
if (ab != null) {
ab.setCustomView(mTitleSwitcher);
ab.setDisplayShowCustomEnabled(true);
ab.setDisplayShowTitleEnabled(false);
}
// Add to hierarchy before accessing layout params.
// int margin = Util.dpToPxOffset(this, 16);
// ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mTitleSwitcher.getLayoutParams();
// lp.leftMargin = margin;
// lp.rightMargin = margin;
mTitleSwitcher.setInAnimation(this, R.anim.abc_fade_in);
mTitleSwitcher.setOutAnimation(this, R.anim.abc_fade_out);
android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
((IslamicLibraryApplication) getApplication()).refreshLocale(this, false);
super.onCreate(savedInstanceState);
// Enable if you use AppCompat 24.1.x.
// Fixes.updateLayoutInflaterFactory(getLayoutInflater());
setContentView(R.layout.activity_settings);
mReplaceFragmentStrategy = new PreferenceScreenNavigationStrategy
.ReplaceFragment(this,
R.anim.abc_fade_in,
R.anim.abc_fade_out,
R.anim.abc_fade_in,
R.anim.abc_fade_out);
if (savedInstanceState == null) {
mSettingsFragment = SettingsFragment.newInstance(null);
getSupportFragmentManager().beginTransaction().add(R.id.content, mSettingsFragment, "Settings").commit();
} else {
mSettingsFragment = (SettingsFragment) getSupportFragmentManager().findFragmentByTag("Settings");
}
getSupportFragmentManager().addOnBackStackChangedListener(this);
mToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
ActionBar ab = getSupportActionBar();
// Cross-fading title setup.
mTitle = getTitle();
mTitleSwitcher = new TextSwitcher(mToolbar.getContext());
mTitleSwitcher.setFactory(() -> {
TextView tv = new AppCompatTextView(mToolbar.getContext());
TextViewCompat.setTextAppearance(tv, R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);
return tv;
});
mTitleSwitcher.setCurrentText(mTitle);
if (ab != null) {
ab.setDisplayHomeAsUpEnabled(true);
ab.setCustomView(mTitleSwitcher);
ab.setDisplayShowCustomEnabled(true);
ab.setDisplayShowTitleEnabled(false);
}
// Add to hierarchy before accessing layout params.
int margin = Util.dpToPxOffset(this, 16);
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mTitleSwitcher.getLayoutParams();
lp.leftMargin = margin;
lp.rightMargin = margin;
mTitleSwitcher.setInAnimation(this, R.anim.abc_fade_in);
mTitleSwitcher.setOutAnimation(this, R.anim.abc_fade_out);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample_main);
// Get the TextSwitcher view from the layout
mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
// BEGIN_INCLUDE(setup)
// Set the factory used to create TextViews to switch between.
mSwitcher.setFactory(mFactory);
/*
* Set the in and out animations. Using the fade_in/out animations
* provided by the framework.
*/
Animation in = AnimationUtils.loadAnimation(this,
android.R.anim.fade_in);
Animation out = AnimationUtils.loadAnimation(this,
android.R.anim.fade_out);
mSwitcher.setInAnimation(in);
mSwitcher.setOutAnimation(out);
// END_INCLUDE(setup)
/*
* Setup the 'next' button. The counter is incremented when clicked and
* the new value is displayed in the TextSwitcher. The change of text is
* automatically animated using the in/out animations set above.
*/
Button nextButton = (Button) findViewById(R.id.button);
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCounter++;
// BEGIN_INCLUDE(settext)
mSwitcher.setText(String.valueOf(mCounter));
// END_INCLUDE(settext)
}
});
// Set the initial text without an animation
mSwitcher.setCurrentText(String.valueOf(mCounter));
}