Android:垂直线性布局-两个图像视图,我希望底部视图的宽度与顶部视图的宽度相同

Android:垂直线性布局-两个图像视图,我希望底部视图的宽度与顶部视图的宽度相同,android,layout,android-layout,android-linearlayout,Android,Layout,Android Layout,Android Linearlayout,我正在尝试获得一个垂直线性布局,以显示一个imageview,并在其下方显示第二个imageview。我希望下部图像视图是顶部图像视图的宽度 我正在尝试当前的布局xml: <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_cont

我正在尝试获得一个垂直线性布局,以显示一个imageview,并在其下方显示第二个imageview。我希望下部图像视图是顶部图像视图的宽度

我正在尝试当前的布局xml:

            <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center">   

                <ImageView
                android:id="@+id/image_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="centerInside"
                android:adjustViewBounds="true"
                android:layout_weight="1"
                />

                <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"> 
                    <ImageView
                    android:id="@+id/spacer"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/spacer"
                    />
                </LinearLayout>

            </LinearLayout>

图像将显示一个“间隔”,它是屏幕的全宽,而不是图像的宽度。间隔是一个淡入淡出的边缘图形,我希望它与上面的图像宽度相同

注意:top imageview的图像是通过编程设置的,可以是横向或纵向图像

有人对如何实现这一目标有什么想法吗


提前谢谢

Hey r3mo使用以下代码,您可以获得您想要实现的目标

<RelativeLayout android:layout_height = "fill_parent" android:layout_width = "fill_parent">
    <ImageView android:layout_width = "wrap_content"
        android:layout_height = "wrap_content" android:id = "@+id/ImageView1"
        android:src = "@drawable/spacer"/>
    <ImageView android:layout_width = "wrap_content"
        android:layout_height = "wrap_content" android:id = "@+id/ImageView2"
        android:src = "@drawable/spacer"
        android:layout_below = "@+id/ImageView1"/>
</RelativeLayout>


使用表布局而不是相对和线性布局来实现这一点,因为表布局自动为所有行提供相同的列。

A
RelativeLayout
即可。使用下面的
layout\u
实现垂直排序,并使用
layout\u widt=“match\u parent”
使用
layout\u alignLeft
layout\u alignRight
约束使底部图像视图尽可能宽:

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

    <ImageView
        android:id="@+id/image_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:scaleType="centerInside"/>

    <ImageView
        android:id="@+id/spacer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/image_view"
        android:layout_alignLeft="@id/image_view"
        android:layout_alignRight="@id/image_view"
        android:background="@drawable/spacer" />

</RelativeLayout>

(是的,我知道。这是一个老问题,但没有好的答案,而且被社区搞砸了。)

改用RelativeLayout。。。将两个图像放在同一相对位置。。。用你这样的方式使用多个布局是没有意义的。谢谢你的回复。我不知道使用相对布局如何确保下部图像与顶部图像的宽度完全相同。尝试过之后,如果relativelayout宽度为fill\u parent,上面的imageview宽度为fill\u parent,下面的imageview宽度为fill\u parent或wrap\u content,我没有得到想要的结果。
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true" >

    <ImageView
        android:id="@+id/image_view"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:adjustViewBounds="true"
        android:scaleType="centerInside"
        android:background="#f00"/>

    <ImageView
        android:id="@+id/spacer"
        android:layout_width="fill_parent"
        android:layout_height="10dp"
        android:layout_below="@id/image_view"
        android:layout_alignLeft="@id/image_view"
        android:layout_alignRight="@id/image_view"
        android:background="#0f0" />

</RelativeLayout>