【问题标题】:unable to align views horizontally in linear layout无法在线性布局中水平对齐视图
【发布时间】:2012-09-27 19:25:45
【问题描述】:

我正在尝试将视图水平放置在线性布局中,以便我可以水平对齐这些视图,但不能彼此相邻。我尝试提供边距、填充值等,但对我没有任何作用。所有视图仍然彼此相邻放置。

我想要最右边的数字时钟和中间的 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>

【问题讨论】:

    标签: android android-linearlayout alignment


    【解决方案1】:

    如果你想对齐更多的东西Relatively,这样东西总是在左边缘,等等,你应该使用RelativeLayout。它使您可以更灵活地处理此类事情。

    【讨论】:

      【解决方案2】:

      您应该使用相对布局。用它来制作布局要容易得多。在您的情况下,它们保留在每个旁边,因为我猜您已将 android:layout_width="wrap_content" 设置为尝试将其更改为 android:layout_width="match_parent" 并尝试。

      【讨论】:

        猜你喜欢
        • 2016-09-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-19
        • 1970-01-01
        • 1970-01-01
        • 2011-10-22
        • 2015-12-01
        相关资源
        最近更新 更多