0

I have four buttons where I want a text switcher to change the text when another button is selected. For my switcher I want the text to be centered inside of the button view, I would like to know how this can be done as I am having a hard time getting the text to center inside of the button .

Shakey
  • 37
  • 8

1 Answers1

1

TextSwitcher animates the current text out and animates the new text in. so

On create

    private TextSwitche  mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
        mSwitcher.setFactory(this);
 Button nextButton = (Button) findViewById(R.id.one);
    nextButton.setOnClickListener(this);

and

public View makeView() {
        Button b= new Button(this);
        b.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL);
       b.setTextSize(70);
        b.setTextColor(Color.RED);
        return b;
    }

in xml

   <Button android:id="@+id/one"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="one"
        android:textStyle="bold|italic" />  
     <Button android:id="@+id/two"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Switch"
        android:textStyle="bold|italic" />                                         
   <TextSwitcher android:id="@+id/switcher"
       android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

I have not tested this code but i think it help for you.if you want more information about textSwitcher go to its Documentation. and Android, make text switcher central?

Community
  • 1
  • 1
Horrorgoogle
  • 7,858
  • 11
  • 48
  • 81
  • Ok I am going to give this try, as I have my switcher and viewfactory set up, just wanted to find out how to center the text from the text switcher inside the button view. – Shakey Jan 11 '12 at 14:24