2012-10-07 62 views
0

我試圖在線性佈局內水平放置視圖,這樣我可以水平對齊這些視圖,但不能彼此相鄰。我試圖給邊際,填充值等,但沒有爲我工作。所有的意見都保持在一起。無法在線性佈局中水平對齊視圖

我希望數字時鐘位於最右側,WiFi圖像位於中央。 請建議我應該使用什麼來使用最小硬代碼將視圖與分隔對齊。

<LinearLayout 
    android:id="@+id/top_bar_id" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/top_bar" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@+id/signal_id" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/signal1" /> 

    <ImageView 
     android:id="@+id/nosim_id" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <ImageView 
     android:id="@+id/wifi_id" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/wifi1" /> 

    <ImageView 
     android:id="@+id/battery_id" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/battery1" 
     /> 

    <DigitalClock 
     android:id="@+id/digClock_id" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     /> 

</LinearLayout> 

回答

1

如果要對齊東西更Relatively,這樣的東西總是在左邊,等等,你應該使用RelativeLayout。它給你更多的靈活性來處理這樣的事情。

+0

謝謝..相對佈局工作 –

+0

很高興幫助:) – Gio

0

您應該使用相對佈局。用它做佈局要容易得多。在你的情況下,他們仍然是每個旁邊,因爲我想你已經設置android:layout_width="wrap_content"嘗試將其更改爲android:layout_width="match_parent"並嘗試。