How can I centralise my text switcher? I've tried set gravity but it doesnt seem to work.
ts.setFactory(new ViewFactory() {
public View makeView() {
TextView t = new TextView(this);
t.setTypeface(tf);
t.setTextSize(20);
t.setTextColor(Color.WHITE);
t.setText("my text switcher");
t.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
return t;
}
});
That code is OK, you need to set the parent textSwitcher width to fill_parent
either in XML with
<TextSwitcher android:layout_width="fill_parent" ...
or in code
import android.widget.LinearLayout.LayoutParams;
//...
textSwitcher=...
textSwitcher.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With