private ViewFactory viewFactory = new ViewFactory() { public View makeView() { LayoutInflater inflater = LayoutInflater.from(TextSwitcherTest.this); TextView textView = (TextView) inflater.inflate(R.layout.textView, null); return textView; } };
mSwitcher.setFactory(new ViewFactory() {
mSwitcher = (TextSwitcher) findViewById(R.id.textSwitcher); mSwitcher.setFactory(new ViewFactory() { public View makeView() { // create new textView and set the properties like clolr, size etc TextView myText = new TextView(MainActivity.this); myText.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL); myText.setTextSize(36); myText.setTextColor(Color.BLUE); return myText; } }); // Declare the in and out animations and initialize them Animation in = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left); Animation out = AnimationUtils.loadAnimation(this,android.R.anim.slide_out_right); // set the animation type of textSwitcher mSwitcher.setInAnimation(in); mSwitcher.setOutAnimation(out);
public class CustomTextSwitcher extends TextSwitcher { private static final long SHOW_TEXT_ANIMATION_TIME = 100; public CustomTextSwitcher(Context context, AttributeSet attrs) { super(context, attrs); init(attrs); } private void init(AttributeSet attrs) { this.setFactory(new ViewFactory() { @Override public View makeView() { return new TextView(new ContextThemeWrapper(context, attrs.getStyleAttribute()), null, 0); } }); Animation in = AnimationUtils.loadAnimation(context, android.R.anim.fade_in); Animation out = AnimationUtils.loadAnimation(context, android.R.anim.fade_out); in.setDuration(SHOW_TEXT_ANIMATION_TIME); out.setDuration(SHOW_TEXT_ANIMATION_TIME); this.setInAnimation(in); this.setOutAnimation(out); } }
sw.setFactory(new ViewFactory() {
mSwitcher.setFactory(new ViewFactory() {
vs.setFactory(new ViewFactory(){