2012-05-29 43 views
0

我用這個代碼繪製以下行如何按鈕之間設置空間,使文本在一行

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
     android:layout_weight=".25" 
    android:layout_height="fill_parent" 

    android:orientation="horizontal" 



    > 
    <Button 
     android:id="@+id/Chemo" 
     android:layout_width="match_parent" 
     android:layout_weight="0.33" 
     android:layout_height="wrap_content" 
     android:text="Chemo" 
     android:background="@drawable/firstbuttoncolorstyle" 
     android:textColor="@drawable/firstbuttontextstyle" 
     android:layout_gravity="center" 
     android:textSize="22dp" 

     /> 

    <Button 
     android:id="@+id/inpatient" 
        android:layout_width="match_parent" 
     android:layout_weight="0.33" 
     android:layout_height="wrap_content" 
     android:text="inpatient" 
     android:background="@drawable/firstbuttoncolorstyle" 
     android:textColor="@drawable/firstbuttontextstyle" 
     android:layout_gravity="center" 
     android:textSize="22dp" 
     /> 

    <Button 
     android:id="@+id/Mgmt" 
    android:layout_width="match_parent" 
    android:layout_weight="0.33" 
    android:layout_height="wrap_content" 
    android:text="Mgmt" 
    android:background="@drawable/firstbuttoncolorstyle" 
    android:textColor="@drawable/firstbuttontextstyle" 
    android:layout_gravity="center" 
    android:textSize="22dp" 
    /> 
     </LinearLayout>  
    <LinearLayout 
    android:layout_width="match_parent" 
     android:layout_weight=".25" 
    android:layout_height="wrap_content" 

    android:orientation="horizontal" 

    > 
    <Button 
     android:id="@+id/PFinder" 
        android:layout_width="match_parent" 
     android:layout_weight="0.23" 
     android:layout_height="wrap_content" 
     android:text="Patient" 
     android:background="@drawable/secondbuttoncolorstyle" 
     android:textColor="@drawable/secondbuttontextstyle" 
        android:layout_gravity="center" 
     android:textSize="22dp" 
     /> 

    <Button 
     android:id="@+id/Afinder" 
        android:layout_width="match_parent" 
     android:layout_weight="0.23" 
     android:layout_height="wrap_content" 
     android:text="Appointement" 
     android:background="@drawable/secondbuttoncolorstyle" 
     android:textColor="@drawable/secondbuttontextstyle" 
        android:layout_gravity="center" 
     android:textSize="22dp" 
     /> 

    <Button 
     android:id="@+id/Calender" 
        android:layout_width="match_parent" 
     android:layout_weight="0.23" 
     android:layout_height="wrap_content" 
     android:text="Calender" 
     android:background="@drawable/secondbuttoncolorstyle" 
     android:textColor="@drawable/secondbuttontextstyle" 
        android:layout_gravity="center" 
     android:textSize="22dp" 
     /> 

    </LinearLayout> 

     <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
     android:layout_weight=".25" 
    android:layout_height="wrap_content" 

    android:orientation="horizontal" 

    > 
     <Button 
     android:id="@+id/Profile" 
        android:layout_width="match_parent" 
     android:layout_weight="0.33" 
     android:layout_height="wrap_content" 
     android:text="Profile" 
     android:background="@drawable/thirdbuttoncolorstyle" 
     android:textColor="@drawable/secondbuttontextstyle" 
        android:layout_gravity="center" 
     android:textSize="22dp" 
     /> 

     <Button 
     android:id="@+id/Clear" 
        android:layout_width="match_parent" 
     android:layout_weight="0.33" 
     android:layout_height="wrap_content" 
     android:text="Clear" 

     android:background="@drawable/thirdbuttoncolorstyle" 
     android:textColor="@drawable/secondbuttontextstyle" 
        android:layout_gravity="center" 
     android:textSize="22dp" 

     /> 

    <Button 
     android:id="@+id/Logout" 
     android:layout_width="match_parent" 
     android:layout_weight="0.33" 
     android:layout_height="wrap_content" 
     android:text="Logout" 
     android:background="@drawable/thirdbuttoncolorstyle" 
     android:textColor="@drawable/secondbuttontextstyle" 
     android:layout_gravity="center" 
     android:textSize="22dp" 


     /> 



    </LinearLayout> 



       <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
     android:layout_weight="0.25" 
    android:layout_height="wrap_content" 

    android:orientation="horizontal" 

    > 
      <ImageButton 
    android:id="@+id/maillme" 
       android:layout_width="wrap_content" 

    android:layout_height="wrap_content" 
    android:background="@drawable/mail" 
     android:layout_gravity="center" 
    /> 


       <ImageButton 
    android:id="@+id/callme" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/call" 
     android:layout_gravity="center" 
    /> 

    </LinearLayout> 



    </LinearLayout> 

但下面是輸出

如何在按鍵之間設置空間,使例如,在一個行壓延字

問候

回答

1

的間距可以使用android:layout_marginRightandroid:layout_marginLeft等。屬性,你應該定義android:layout_width="WRAP_CONTENT"以防止你的日曆按鈕和下一個按鈕已經有的行爲。

2

通過看你的例子,你應該減少textSize到20 ...所以calendar & impatient將適當適當。

只是一個提示:對於文本大小使用sp,對於控件的高度和寬度使用dp

保證金您有:android:layout_marginRightandroid:layout_marginLeft

希望它能幫助!

0

設置android:layout_marginLeft = "5dp"每個按鈕後首先Button,我認爲你可以使用android:singleLine = "true"保持文本在一行。

還將高度設置爲所有按鈕eual,並在主佈局上使用android:layout_height = "wrap_content"

0

首先,你應該使用樣式通過重用類似的屬性,以減少代碼長度:gravity, layout_height, textColor, ...

至於在某些按鈕換行符。如果您只處理平板電腦,則可以使用layout_width="wrap_content"來避免換行符,併爲每個按鈕設置相同的高度。

要在每個按鈕之間留出一點空隙,請使用已提及的layout_marginLeft

相關問題