ToogleButton右对齐文本标签 [英] ToogleButton align text label on the right

查看:124
本文介绍了ToogleButton右对齐文本标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要对齐在 ToogleButton 文本上吧,成为绿/白时pressing的权利。

I want to align the text in a ToogleButton on the right of that bar that became green/white when pressing it.

要更加明确,我将张贴code,也是导致我现在有。

To be more explicit I will post the code and also the result I have now.

 <ToggleButton android:id="@+id/ToggleButton01"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  layout_gravity="center_vertical"
                  android:textOff="Off"
              android:textOn="On"/>

 ToggleButton onOffButton = (ToggleButton) findViewById(R.id.ToggleButton01);
 onOffButton.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
 onOffButton.setPadding(0, 0, 5, 0);

和的结果:

and the result:

我想酒吧和文字不能重复。

I want the bar and the text to not be overlapped.

推荐答案

你试过了attibute重力?

have you tried the attibute gravity?

android:gravity="center"

之间的性差异的android:layout_gravity =中心安卓重力=中心的是,第一个将围绕你的查看你的布局中的第二将集中的,内容查看

the diference between android:layout_gravity="center" and android:gravity="center" is that the first one will center your View within your layout and the second will center the content of that View.

这是我对你的按钮布局:

This is my layout of your button:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ToggleButton android:id="@+id/ToggleButton01"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center_vertical"
                  android:textOff="Off"
                  android:gravity="center"
              android:textOn="On"/>

</LinearLayout>

这篇关于ToogleButton右对齐文本标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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