Android 如何将图像放置在另一个图像上,其中图像的中间应与下面图像的底部对齐

Android 如何将图像放置在另一个图像上,其中图像的中间应与下面图像的底部对齐,android,imageview,layoutparams,Android,Imageview,Layoutparams,我有一个横幅,我显示在一个安卓布局。在这个横幅上,我有两个头像,我想彼此相邻显示,最重要的是,我想让它们显示在y轴上这两个头像的中间点与这些头像所在的横幅底部对齐的位置。 你会怎么做 编辑: 换句话说,我想问的是,如何使用下面的参数android:layout_,而不是将imageview的顶部与指定布局的底部对齐,以对齐中心 将它们放在线性布局中,然后给它们一个宽度以填充父对象。然后,可以使用“权重”属性均匀分散宽度 <?xml version="1.0" encoding="utf-8

我有一个横幅,我显示在一个安卓布局。在这个横幅上,我有两个头像,我想彼此相邻显示,最重要的是,我想让它们显示在y轴上这两个头像的中间点与这些头像所在的横幅底部对齐的位置。

你会怎么做

编辑:

换句话说,我想问的是,如何使用下面的参数android:layout_,而不是将imageview的顶部与指定布局的底部对齐,以对齐中心


将它们放在线性布局中,然后给它们一个宽度以填充父对象。然后,可以使用“权重”属性均匀分散宽度

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


    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/clock" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/clock" />

</LinearLayout>

不幸的是,没有直接的布局参数将中心点与另一条边对齐。如果你的头像的高度是固定的,你可以添加一些半高的填充物,这样他们就可以排成一行了;i、 e

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/banner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="25dp"
        android:src="@drawable/banner" />

    <ImageView
        android:id="@+id/avatar1"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_alignBottom="@id/banner"
        android:src="@drawable/horse" /> 
    <ImageView
        android:id="@+id/avatar2"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_alignBottom="@id/banner"
        android:layout_toRightOf="@id/avatar1"
        android:src="@drawable/horse" />
</RelativeLayout>

但是,如果这些项目的高度是动态的,那么您需要创建自定义的
ViewGroup
容器,以便您可以测量化身高度(在
onMeasure()
)并在运行时应用填充(或其他偏移值)