android – 按钮上面的文字

我是 Android的新手,我需要在我的活动中添加单选按钮,但是我需要将文本放在子弹按钮上.

任何帮助请.我发现以下,虽然我不明白@ drawable / main_selector和@ style / TabStyle.

Radiobutton with text on top

任何人都可以给我一个101指南.

UPDATE

我根据一些建议使用了以下内容,但没有工作:

<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioButton
    android:text="something that is on top"
    android:id="@+id/toggle_tab_left"
    android:button="?android:attr/listChoiceIndicatorSingle"        
    style="@null"/>

<RadioButton 
    android:button="?android:attr/listChoiceIndicatorSingle"
    android:text="something that is on top"
    android:id="@+id/toggle_tab_right"
    style="@null"/>
</RadioGroup>

更新2

我从Warpzit得到了我的解决方案,但是我将这个问题标记为已回答,有人可以在下面的对齐问题上帮助我.
我将在一行中有5个单选按钮,其中一些将有更长的文本分割为2行.当文字适合屏幕,因为景观,或在平板电脑上,所有文字应该在一行:

更新3

…根据屏幕大小,文本可以分割成不同的行数.它不总是标准的

解决方法

@ style / TabStyle只是一个应用的样式,可以忽略它. @ drawable / main_selector是根据情况切换的图形.您可以阅读有关选择器 here的更多信息.

获取文本的示例:

<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioButton
    android:text="Text on top"
    android:button="@null"
    android:background="#f00"
    android:layout_weight="1"/>

<RadioButton 
    android:text="Text on top"
    android:button="@null"
    android:background="#0f0"
    android:layout_weight="1"/>
</RadioGroup>

将给出以下结果:

如果您希望文本出现在按钮上方,您可以使用以下xml:

<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioButton
    android:text="Text on top"
    android:button="@null"
    android:drawableBottom="@android:drawable/btn_radio"
    android:gravity="center"
    android:layout_weight="1"/>

<RadioButton
    android:text="Text on top"
    android:button="@null"
    android:drawableBottom="@android:drawable/btn_radio"
    android:gravity="center"
    android:layout_weight="1"/>
</RadioGroup>

这将给出以下结果:

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...