如何对齐3行按钮,android?

我在父级中有线性垂直布局.
然后是底部的水平线性布局,包括3个按钮

我希望活动最左侧的第一个按钮位于底部
中间的第二个按钮
和最右边的第3个按钮

这是xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

   <ImageView
    android:id="@+id/viewImageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:contentDescription="@null"
    android:src="@drawable/ic_launcher" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:layout_gravity="fill_vertical"
        android:text="Button" />
</LinearLayout>

解决方法

对于那些类型的对齐(父对象的最左边的一个按钮,中间的另一个按钮以及父布局的最右边的一个按钮)RelativeLayout比LinearLayout更方便.因为如果你使用RelativeLayout作为你的按钮的父布局你可以使用android:layout_alignParentLeft =“true”表示你想要在最左边对齐的一个按钮,android:layout_centerInParent =“true”在中心和android中对齐:layout_alignParentRight =“true”以对齐右侧角落的按钮.

试试这个..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

   <ImageView
    android:id="@+id/viewImageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:contentDescription="@null"
    android:src="@drawable/ic_launcher" />

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Button" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Button" />
</RelativeLayout>

</LinearLayout>

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...