Android在ImageButton顶部覆盖文本

时间:2018-10-02 16:58:41

标签: android android-layout kotlin

我有一个图像按钮,想要在其上方放置一个描述性文本。还需要ImageButton为父级宽度的1/3,因此不能使用ConstraintLayout或LinearLayout。有任何想法吗?

1 个答案:

答案 0 :(得分:1)

尝试将ImageViewTextView包裹在RelativeLayout中,如下:

<RelativeLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

并在父版式中设置android:weightSum=3。有了所需的布局后,请点击RelativeLayout而不是使用ImageButton

相关问题