2017-11-11 118 views
0

我學習XML現在定位在一排中間水平2元,我需要一點點幫助如何在相對佈局

我需要做的是把一個TextView,隨後在該中心的ImageView的水平。

下面的代碼:

<ImageView 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:src="@drawable/party_p" 

     android:layout_toEndOf="@id/TextView_congrats" 
     android:layout_marginTop="30dp" /> 

    <TextView 
     android:id="@+id/TextView_congrats" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Congrats Laura!" 
     android:textSize="30sp" 
     android:fontFamily="sans-serif-light" 
     android:textColor="@android:color/white" 

     android:layout_marginTop="30dp" 
     android:paddingRight="20dp"/> 

我使用相對佈局爲這個項目,我需要知道如何把這些元素的水平居中。

+0

你可以換他們兩個在的LinearLayout並給予了'centerHorizo​​ntal =「真」'價值,或者只是添加此'centerHorizo​​ntal =「真」'既他們會橫向居中 –

回答

1

在兩個視圖試試這個屬性:

android:layout_centerHorizontal="true"