找回密碼
 註冊
搜索
查看: 1438|回復: 0

[教學] Android 按鈕自動調整寬度

[複製鏈接]
發表於 2016-12-14 02:58:53 | 顯示全部樓層 |閱讀模式
 
Push to Facebook
button.png
如果想在畫面的「某一列」,放2個按鈕,而這2個按鈕要平均分配寬度,程式如下:


<Button android:id="@+id/button1" android:layout_height="wrap_content" android:text="delete" android:layout_width="fill_parent" android:layout_weight="1"/>
<Button android:id="@+id/button2" android:layout_height="wrap_content" android:text="unlink" android:layout_width="fill_parent" android:layout_weight="1"/>



如果不要按鈕之間有留白,以下3種作法

(1) 把padding設負值

(2) 給Button 設android:background="#000" 隨便給一個顏色,但是高度會變小,要自己設一下

(3) 自己做一張.png圖,給Button 設android:background="X圖"


 
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|小黑屋|TShopping

GMT+8, 2025-4-30 21:26 , Processed in 0.031792 second(s), 24 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回復 返回頂部 返回列表