2013-07-21 42 views
1

我一直無法讓這個LinearLayout移動到它的父親RelativeLayout的垂直中心。我嘗試了很多方法,也許我使用了錯誤的方法,但我不確定。有人可以檢查它,看看我需要添加什麼。謝謝。 LinearLayout右側有一些TextViews,但我沒有包含它們,因爲您不需要它們,但只記得佈局需要位於RelativeLayout的垂直中心,而不是整個中心。ImageView到RelativeLayout的中間 - Android

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/background_card" 
    android:orientation="horizontal" 
    android:padding="5dip" > 

<!-- ListRow Left sied Thumbnail image --> 
    <LinearLayout android:id="@+id/thumbnail" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="3dip"  
     android:layout_alignParentLeft="true" 
     android:gravity="center" 
     android:background="@drawable/image_bg" 
     android:layout_marginRight="5dip"> 

    <ImageView 
     android:id="@+id/list_image" 
     android:layout_width="50dip" 
     android:layout_height="50dip" 
     android:src="@drawable/thumb"/> 

</LinearLayout> 

回答

3

如果需要垂直居中一個元素的RelativeLayout裏面,你的具體情況的LinearLayout,再加入android:layout_centerVertical="true"屬性的LinearLayout中。

1

第一相對內部全部採用線性的是不是一個好主意,我喜歡ü改變這種狀況,但仍然如果u想保持一致,在middel不能動線佈局,我只好移動UR圖像

現在有有很多方法,如

android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_centerVertical="true"

,再加上你可以給保證金-inputs手動

android:layout_marginTop="162dp" android:layout_marginleft="80dp" ..

首先嚐試這些,但仍然強烈建議使用線性或相對,並且可以始終在設計視圖中拖動您的UI。

+1

我必須使用兩種不同的佈局,因爲每種佈局都有不同的背景xml文件。現在我想知道如果沒有可繪製的xml文件之一,我是否可以做到這一點 – ThePoloDoc

+0

是的,你可以,但基本的想法是保持它們在最開始的時候是相同的,也就是相對的或者是Linear ..,但是就像你剛剛做的那樣你可以使用相對和你可以通過使用'android:layout_alignParentTop =「true」android:layout_centerHorizo​​ntal =「true」android:layout_centerVertical =「true」'這些和他們手動拖動它們或給邊緣調整你的用戶界面... – yug

相關問題