机器人,使文本转换器的中央? [英] Android, make text switcher central?

查看:105
本文介绍了机器人,使文本转换器的中央?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何集中我的文字转换器?我试过一套重力,但它似乎没有工作。

  ts.setFactory(新的ViewFactory(){
        公共查看makeView(){
        TextView的T =新的TextView(本);
        t.se​​tTypeface(TF);
        t.se​​tTextSize(20);
        t.se​​tTextColor(Color.WHITE);
        t.se​​tText(我的文字转换器);
        t.se​​tGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
        返回吨;
    }
    });


解决方案

这code是OK,你需要设置的父textSwitcher 宽度FILL_PARENT

无论是在XML与

 < TextSwitcher的android:layout_width =FILL_PARENT...

或code

 进口android.widget.LinearLayout.LayoutParams;
// ...
textSwitcher = ...
textSwitcher.setLayoutParams(新的LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));

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));

这篇关于机器人,使文本转换器的中央?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆