Android文字下方的图标(按钮) [英] Android Text Below Icon (button)

查看:381
本文介绍了Android文字下方的图标(按钮)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个主输入界面。我将创建一个六个按钮,每个按钮将打开另一个活动。对于每个按钮,我希望它都有一个大图标,该按钮下方带有文字。目前,我可以在按钮上显示图像,但是我不知道如何使文本显示在按钮下方。我试图将文本直接放在图片上,但是效果不太好。这是按钮的第一行(两个按钮)的部分

I am trying to create a main entry interface. I will create a six buttons, and each button will open another activity. For each button, I want it have an big icon with text below the button. Currently, I can have image on the button, but I do not know how to make the text to display below the button. I tried to place the text directly on the image, but it doesn't look good. Here is the portion for the first row (two buttons) of button

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="horizontal"
    android:weightSum="2" >

    <Button
        android:id="@+id/btn1"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@drawable/ic_my_icon" />

    <Button
        android:id="@+id/btn2"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@drawable/ic_my_icon2" />
</LinearLayout>

这就是我在说的。除此之外,我希望图标为椭圆形按钮。
结果我想要的外观看起来像这篇文章中的图像,除了我想要六个带有图像和文本的椭圆形按钮。
带有中心和文本图标的圆形按钮在图标下

This is what I am talking about. Other than that I want the icon to be an oval button. The result I want kind of look like the image in this post, except I would like six oval button with images and text. Round buttons with icon in center and text under icon

非常感谢您的帮助。

推荐答案

按如下所示使用 drawableTop 属性:

<Button
    android:id="@+id/btn2"
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:text="This text is below the image"
    android:drawableTop="@drawable/ic_my_icon2" /> 

请参见参考资料 android:drawableTop 按钮文档,其中包含 drawableLeft

See the reference android:drawableTop and this simple example on Button documentation with drawableLeft.

这篇关于Android文字下方的图标(按钮)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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