Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何让一个图像与另一个图像匹配';用相对长度表示高度?_Android_Android Layout_Android Relativelayout - Fatal编程技术网

Android 如何让一个图像与另一个图像匹配';用相对长度表示高度?

Android 如何让一个图像与另一个图像匹配';用相对长度表示高度?,android,android-layout,android-relativelayout,Android,Android Layout,Android Relativelayout,我想把ImageB放在ImageA之上。我应该如何做到这一点 注: 我不想固定这两幅图像的高度,以便保持它们的纵横比 图像A和图像B的高度不同 任何帮助都将不胜感激 试试这段代码 <RelativeLayout android:layout_height="wrap_content" android:layout_width="match_parent"> <ImageView android:id="@+id/imageA"

我想把
ImageB
放在
ImageA
之上。我应该如何做到这一点

注:

  • 我不想固定这两幅图像的高度,以便保持它们的纵横比
  • 图像A
    图像B
    的高度不同

    
    

任何帮助都将不胜感激

试试这段代码

<RelativeLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <ImageView
    android:id="@+id/imageA"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:scaleType="fitCenter"
    android:src="@drawable/imageA" 
    android:adjustViewBounds="true"/>

    <!-- How to match let imageB matches imageA's height ? -->
    <ImageView
    android:id="@+id/imageB"
        android:layout_alignTop="@id/imageA" // add it
        android:layout_alignBottom="@id/imageA" // add it
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_alignParentTop="true" // remove it
        android:layout_alignParentRight="true"
        android:src="@drawable/imageB"/>
</RelativeLayout>

希望有此帮助

请尝试此代码

<RelativeLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <ImageView
    android:id="@+id/imageA"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:scaleType="fitCenter"
    android:src="@drawable/imageA" 
    android:adjustViewBounds="true"/>

    <!-- How to match let imageB matches imageA's height ? -->
    <ImageView
    android:id="@+id/imageB"
        android:layout_alignTop="@id/imageA" // add it
        android:layout_alignBottom="@id/imageA" // add it
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_alignParentTop="true" // remove it
        android:layout_alignParentRight="true"
        android:src="@drawable/imageB"/>
</RelativeLayout>


希望这个帮助

你可以使用android:alignTop=“@id/imageA”和alignBottom=“@id/imageA”我同意@Phan Văn Linh ans试试这个方法。你可以使用android:alignTop=“@id/imageA”和alignBottom=“@id/imageA”我同意@Phan Văn Linh ans试试这个方法。