簡體   English   中英

如何將圖像放在按鈕的中心

[英]how to put image in the center of the button

我想將圖像放在按鈕的中央,我只想使用線性布局,任何幫助都會很棒,這是我的布局。

    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:weightSum="5"
    >
  <Button
 android:layout_width="0dp"
 android:layout_height="match_parent"
  android:layout_weight="1"
 android:layout_gravity="center"
 android:drawableTop="@drawable/home"
/>
    </LinearLayout>

因此,您希望圖像居中: Simplest way to achieve this is


腳步

  1. 無需linear layout
  2. 使用圖片( .png.jpg )並將其用作drawable
  3. 將該drawable資源設置為button的背景

好的,我已經做到了。這可以通過使用Imagebutton代替Button來解決

   <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:weightSum="5"
    >
   <ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/button1"
android:layout_gravity="center"
android:src="@drawable/home"
/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM