[英]How to give Fixed width and height for Button in Android
我是android開發的初學者。 我剛在main.xml文件中創建了一個按鈕
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:text="Click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
我只給android的整數值:但我得到錯誤錯誤:錯誤:不允許整數類型
如何為Button提供固定的寬度和高度? android:layout_width和android:Width之間的主要區別是什么?
謝謝。
要創建具有固定高度和寬度的按鈕,您可以在px或dp中給出值。
在dp中給出值更方便,因為android會自動縮放ldpi,mdpi和hdpi設備中的高度和寬度。
<Button
android:text="Click"
android:layout_width="100dp"
android:layout_height="50dp"
/>
試試這樣
<Button
android:text="Click"
android:layout_width="200dip"
android:layout_height="wrap_content"
/>
其中dip是密度獨立像素
您需要提供如下數值,
<Button
android:text="Click"
android:layout_width="250dp"
android:layout_height="50dp" />
使用整數(25,40 ...)+類型(DP,DIP,PX):喜歡
android:layout_width="25dp"
你為什么要這樣做。 更好地使用包裝內容,或使用重量標簽,因此它將支持並在所有尺寸的設備上看起來都很好。
你需要這樣做
<Button android:layout_Width="150dp"
android:layout_Height="50dp" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.