[英]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
linear layout
.png
或.jpg
)並將其用作drawable
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.