如何在Android中水平对齐三个图像视图?

如何在Android中水平对齐三个图像视图?,android,Android,我想在屏幕底部以相等的权重显示三个imageview。但是图像的大小不是固定的。我想显示两个图像,其中一个应该隐藏,我应该怎么做? 如何调整三个应并排排列的图像视图之间的间距,以及第三个图像视图不应与屏幕上可见的两个图像视图重叠 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_

我想在屏幕底部以相等的权重显示三个
imageview
。但是图像的大小不是固定的。我想显示两个图像,其中一个应该隐藏,我应该怎么做?
如何调整三个应并排排列的
图像视图之间的间距,以及第三个
图像视图不应与屏幕上可见的两个
图像视图重叠

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:background="@drawable/main_imge_1"
   android:orientation="vertical" >

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

    android:background="#F9F939"
    android:src="@drawable/ic_launcher"
    android:layout_toLeftOf ="@+id/imageView6"
  android:layout_alignParentBottom="true"
    android:padding="15dp" />

 <ImageView
    android:id="@+id/imageView6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#54F71D"

    android:src="@drawable/ic_launcher"
    android:layout_alignParentBottom="true"
    android:padding="15dp"
    android:layout_margin="10dp" />

  <ImageView
    android:id="@+id/imageView7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#1DF7AB"
    android:src="@drawable/ic_launcher"
  android:layout_alignParentBottom="true"
    android:layout_toRightOf="@+id/imageView6"
    android:padding="15dp" />

</RelativeLayout>

试试这种方法

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center|bottom" >

    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="#F9F939"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="#54F71D"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/imageView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="#1DF7AB"
        android:src="@drawable/ic_launcher" />

</LinearLayout>

输出

试试这种方法

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center|bottom" >

    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="#F9F939"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="#54F71D"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/imageView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="#1DF7AB"
        android:src="@drawable/ic_launcher" />

</LinearLayout>

输出


根据我能够解密的内容,您可能正试图实现以下目标:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 >

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:gravity="center_horizontal">


        <ImageView
    android:id="@+id/imageView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#F9F939"
    android:src="@drawable/ic_launcher"
    android:padding="15dp"
    android:layout_weight="1"
    />

  <ImageView
    android:id="@+id/imageView6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#F9F939"
    android:src="@drawable/ic_launcher"
    android:padding="15dp"
    android:layout_weight="1"
    />

  <ImageView
    android:id="@+id/imageView7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#F9F939"
    android:src="@drawable/ic_launcher"
    android:padding="15dp"
    android:layout_weight="1"
    />


    </LinearLayout>

</RelativeLayout>

结果是:


关键是使用一个封闭的
LinearLayout
来保存
ImageView
s,并将
LinearLayout
对齐到
RelativeLayout
的底部。根据我能够解密的内容,您可能正试图实现这一点:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 >

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:gravity="center_horizontal">


        <ImageView
    android:id="@+id/imageView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#F9F939"
    android:src="@drawable/ic_launcher"
    android:padding="15dp"
    android:layout_weight="1"
    />

  <ImageView
    android:id="@+id/imageView6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#F9F939"
    android:src="@drawable/ic_launcher"
    android:padding="15dp"
    android:layout_weight="1"
    />

  <ImageView
    android:id="@+id/imageView7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#F9F939"
    android:src="@drawable/ic_launcher"
    android:padding="15dp"
    android:layout_weight="1"
    />


    </LinearLayout>

</RelativeLayout>

结果是:


关键是使用一个封闭的
线性布局
来容纳
图像视图
s,并使该
线性布局
相对视图的底部对齐

对每个图像视图使用安卓:layout\u weight=“1”。并将您的RelativeLayout替换为Linearlayout。

为每个图像视图使用android:layout\u weight=“1”。并将您的RelativeLayout替换为Linearlayout。

尊敬的用户,欢迎使用StackOverflow。请大声朗读问题的前几行,并告诉我你是否理解它们。然后,请给我解释一下-尤其是最后一句。你想说什么…请写清楚…我想在屏幕底部水平显示threeimageview我该怎么做?基本布局应该是线性的,而不是相对的。“相对”只会在对齐东西时造成麻烦。亲爱的用户,欢迎使用StackOverflow。请大声朗读问题的前几行,并告诉我你是否理解它们。然后,请给我解释一下-尤其是最后一句。你想说什么…请写清楚…我想在屏幕底部水平显示threeimageview我该怎么做?基本布局应该是线性的,而不是相对的。当你把东西对齐的时候,相对的只会引起麻烦。是的!工作如期!谢谢,是的!工作如期!谢谢