Android ImageView内部RelativeLayout不是其父高度
我在create_button.xml中有以下代码:Android ImageView内部RelativeLayout不是其父高度,android,Android,我在create_button.xml中有以下代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="60dp" android:layout_width="wrap_content" android:padding="3dp" android:background="@color/green">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="60dp"
android:layout_width="wrap_content"
android:padding="3dp"
android:background="@color/green">
<ImageView
android:id="@+id/test_button_image"
android:layout_width="wrap_content"
android:src="@drawable/backImage"
android:contentDescription="@string/app_name"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
</ImageView>
</RelativeLayout>
这段代码包含在应用程序的一个片段中,如下所示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:baselineAligned="false"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include android:id="@+id/buttonCreate"
layout="@layout/create_button"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</include>
</LinearLayout>
但我的图像并不是针对60dp的相对长度布局高度,而是扩展到其原始高度
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:background="@color/green"
android:padding="3dp" >
<ImageView
android:id="@+id/test_button_image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:contentDescription="@string/app_name"
android:src="@drawable/backImage" >
</ImageView>
我试图将其布局\u高度
更改为匹配\u父项
,但没有成功。它扩展了全屏高度
如何使此图像与其父图像的高度相同 我认为下面的代码适合您
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="3dp"
android:background="@color/green">
<ImageView
android:id="@+id/test_button_image"
android:layout_width="wrap_content"
android:src="@drawable/backImage"
android:contentDescription="@string/app_name"
android:layout_height="60dp"
android:layout_alignParentTop="true">
</ImageView></RelativeLayout>
用ImageView交换相对布局的高度,反之亦然。试试这个。它永远不会膨胀到原来的高度
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:background="@color/green"
android:padding="3dp" >
<ImageView
android:id="@+id/test_button_image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:contentDescription="@string/app_name"
android:src="@drawable/backImage" >
</ImageView>
将图像视图中的这一行更改为android:layout\u height=“wrap\u content”
为android:layout\u height=“match\u parent”
我尝试过,然后按钮将扩展其主容器布局高度。您希望图像的高度是多少?与RelativeLayout
相同,对吗?是否更改了高度以匹配图像视图的父视图?它永远不会全屏显示,而且您在RelativeLayout
中使用了填充。它确实有效,但我试图找到一种动态绑定到其父级高度的方法。