我需要一些帮助 我无法在 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>
最佳答案
我认为您可以使用 TextView
实现您的想法:
按钮 1 的示例:
<TextView
android:layout_width="wrap_content"
android:background="@drawable/button1_style"
android:drawableTop="@drawable/icon1_48dp"
android:text = "Button1"
android:layout_height="wrap_content"/>
如果需要,为其添加padding
、margin
、drawablePadding
。
关于android - 带有图标或图像的 ImageButton 中未显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40255490/