2012-10-07 59 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"并尝试。