Text上に表示するための最良の方法button(画像付き)

あなたの質問: に表示textするにはどうすればよいimagebuttonですか?
回答text: では表示できませんimageButton。承認された回答で伝える方法も機能しません。
なぜなら
を使用するとof にandroid:drawableLeft="@drawable/buttonok"設定できません。drawablecenterbutton
あなたが使用する場合android:background="@drawable/button_bg"はcolor、あなたのdrawableが変更されます。
Android の世界では、これを行うための何千ものオプションがあります。しかし、ここでは、私の観点から最良の代替案を提供します。(下記参照)
解決策:cardViewで使用LinearLayout
中央に表示されますのでおdrawable/image使いください。LinearLayoutそして、textViewあなたの助けを借りて、これを設定できますtext。cardView背景を にしますtransparent。
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="99dp"
android:layout_margin="16dp"
app:cardBackgroundColor="@android:color/transparent"
app:cardElevation="0dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/your_selected_image"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Happy Coding"
android:textSize="33sp"
android:gravity="center"
>
</TextView>
</LinearLayout>
</androidx.cardview.widget.CardView>
ここでいくつかの用語を説明します:
app:cardBackgroundColor="@android:color/transparent"背景を透明にするcardView
app:cardElevation="0dp"周囲の標高線を非表示にするcardView
app:cardUseCompatPadding="true"の実際のサイズを提供しますcardView。ご利用の際は必ずこちらをご利用くださいcardView
背景としてあなたimage/drawableを設定します。LinearLayout
私の悪い英語で申し訳ありません。
ハッピーコーディング:)