Android Text Below Icon (button)

2020-07-03 10:34发布

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

Thank you very much for your help.

1条回答
等我变得足够好
2楼-- · 2020-07-03 10:41

Use drawableTop attribute as follows:

<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" /> 

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

查看更多
登录 后发表回答