【发布时间】:2012-07-03 03:50:10
【问题描述】:
我正在尝试制作一个水平菜单栏,但是由于某种原因,当我使用权重时,它们不会水平对齐,有什么建议吗?
<LinearLayout
android:id="@+id/bottombuttonslayout"
android:layout_width="match_parent"
android:layout_height="58dp"
android:layout_alignParentBottom="true"
android:weightSum="1.0" >
<LinearLayout
android:id="@+id/listSlotBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".20"
android:gravity="center" >
<ImageView
android:id="@+id/listSlot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:background="@drawable/list" />
</LinearLayout>
<LinearLayout
android:id="@+id/leftArrorSlotBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight=".20" >
<ImageView
android:id="@+id/leftArrowSlot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:background="@drawable/left_arrow" />
</LinearLayout>
<LinearLayout
android:id="@+id/playSlotBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight=".20" >
<ImageView
android:id="@+id/playSlot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:background="@drawable/playing" />
</LinearLayout>
<LinearLayout
android:id="@+id/rightArrowSlotBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight=".20" >
<ImageView
android:id="@+id/rightArrowSlot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:background="@drawable/right_arrow" />
</LinearLayout>
这就是它的样子,它们是垂直对齐的。不是水平的:
编辑
这是遵循第一个建议:
【问题讨论】:
-
它们不会水平对齐,因为
android:layout_gravity="center"仅适用于水平方向的LinearLayout的垂直方向(对于垂直方向的LinearLayout,反之亦然)。您是否尝试在嵌套的 LinearLayouts 上添加android:gravity="center"?或者,您可以随时将它们换成FrameLayout或RelativeLayout之类的东西,这样您就可以更好地控制定位。
标签: android android-layout android-linearlayout android-imageview