Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, make text switcher central?

Tags:

android

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;
    }
    });
like image 832
beans Avatar asked May 02 '26 03:05

beans


1 Answers

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));
like image 116
Daniel Fekete Avatar answered May 03 '26 17:05

Daniel Fekete



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!