2017-01-25 53 views
0

我有一個按鈕幫助,右邊和左邊的邊距爲10dp。然後我在TextView(水平居中)的左邊添加一個按鈕測試,在按鈕help的下方,並向左對齊按鈕help關於對齊的佈局問題

問題在於按鈕測試並不完全對齊按鈕help,如TextViewtest1在按鈕help的右側。

我在做什麼錯?

enter image description here

這裏是我的佈局:

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#ffffff" 
    > 

    <TextView 
     android:id="@+id/mid" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:text="1" 
     android:gravity="center" 
     /> 

    <Button 
     android:id="@+id/help" 
     android:text="Help" 
     android:layout_width="match_parent" 
     android:layout_marginTop="35dp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_height="wrap_content"/> 

    <Button 
     android:id="@+id/test" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/help" 
     android:layout_marginTop="5dp" 
     android:background="#87CEFF" 
     android:text="Test" 
     android:layout_toLeftOf="@id/mid" 
     android:layout_alignLeft="@id/help" 
     /> 

    <TextView 
     android:id="@+id/test1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@id/mid" 
     android:layout_alignBottom="@id/test" 
     android:layout_alignTop="@id/test" 
     android:layout_alignRight="@id/help" 
     android:text="test1\ntest2" 
     android:gravity="center" 
     android:textColor="#0000ff" 
     android:background="#00cc00" 
     />  

</RelativeLayout> 
+0

所以,你想要什麼。 如果您查看佈局的輸出,則按鈕測試沒有完全對齊按鈕幫助(按某些像素),您希望如何顯示視圖 –

+0

。 textview test1無論是幫助的權利。 – narb

+0

你的光線對齊只是給你任何背景顏色,幫助按鈕 –

回答

1

我認爲是幫助按鈕的只是背景。 如果您也使用自定義背景,它會填滿他的所有空間。

+0

這很奇怪,但它的工作原理。謝謝。 – narb

0

在相對佈局中包裝測試按鈕和textview,並將每個父對象左對齊。

+0

太麻煩。從我的角度來看,背景解決方案更好。謝謝。 – narb

0

你的代碼沒有錯只有一件事你必須添加到你的按鈕測試是android:background =「@ android:color/darker_gray」或任何你選擇的顏色,android默認提供了padding padding按鈕。

<Button 
    android:id="@+id/help" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginTop="35dp" 
    android:background="@android:color/darker_gray" 
    android:text="Help" /> 

我已經在上面的代碼中必要的修改嘗試,希望能解決你的問題