文本没有显示在带图标或图像的ImageButton中

jem*_*emz 1 android android-layout android-imagebutton

我需要一些帮助,请不要在我的图标或图像下面或下面显示文字,ImageButton我试图使用TextView但是它弄乱我的按钮我不知道如何显示文本.这是我的xml.

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


    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:orientation="horizontal"
            android:background="#eeeeee" android:layout_marginTop="30dp">

        <ImageButton
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:adjustViewBounds="true"
                android:padding="30dp"
                android:scaleType="fitCenter"
                android:background="@drawable/button1_style"
                android:src="@drawable/icon1_48dp"
                style="@style/Widget.AppCompat.Button.Colored" />

       <ImageButton
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:adjustViewBounds="true"
                android:padding="30dp"
                android:scaleType="fitCenter"
                style="@style/Widget.AppCompat.Button.Colored"
                android:background="@drawable/button2_style"
                android:src="@drawable/icon2_48dp"
                android:tint="#ffffff"

                />

    </LinearLayout>

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:orientation="horizontal"
            android:background="#eeeeee" android:layout_marginBottom="20dp">

    <ImageButton
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:adjustViewBounds="true"
                android:padding="30dp"
                android:scaleType="fitCenter"
                style="@style/Widget.AppCompat.Button.Colored"
                android:src="@drawable/icon3_48dp"
                android:background="@drawable/button3_style"
                android:tint="#ffffff"
              />

        <ImageButton
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:adjustViewBounds="true"
                android:padding="30dp"
                android:scaleType="fitCenter"
                style="@style/Widget.AppCompat.Button.Colored"
                android:src="@drawable/icon4_48dp"
                android:background="@drawable/button4_style"
               />
    </LinearLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

pho*_*van 6

我想你可以用TextView你的想法:

button1的示例:

<TextView
    android:layout_width="wrap_content"
    android:background="@drawable/button1_style"
    android:drawableTop="@drawable/icon1_48dp"
    android:text = "Button1"
    android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)

添加padding,margin,drawablePadding对于它,如果你需要的.