Java 图像视图未包装内容

Java 图像视图未包装内容,java,android,imageview,Java,Android,Imageview,我有一个ImageView包装: 它的正下方是一个文本视图。不幸的是,根据设备的屏幕大小,它要么将其向下推到视图中,要么将其移出视图 我可以“破解”它,但它不想 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android

我有一个ImageView包装:


它的正下方是一个文本视图。不幸的是,根据设备的屏幕大小,它要么将其向下推到视图中,要么将其移出视图

我可以“破解”它,但它不想

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="16dp"
android:orientation="vertical"
tools:context="MapFragment">

<ImageView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/oncmap"/>

<TextView
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:text="Neptune"
    style="@style/sectionHeader"/>

<TextView
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:paddingTop="16dp"
    android:text="@string/info"
    style="@style/text"/>


将以下字段添加到ImageView:

android:scaleType="fitXY"
android:adjustViewBounds="true"

如果您尝试为例如4~6MB添加大尺寸图像,并且您正在使用drawable,那么您将得到类似->java.lang.RuntimeException:Canvas:尝试绘制太大(537528960字节)位图的错误

对于java,请在android studio中执行此操作,但其他人的概念仍然相同。执行此操作可在后台将图像插入应用程序中,适用于大小图像

基本上是将您的图像从(高分辨率)可绘制移动到可绘制xxhdpi,这将在应用程序->分辨率->mipmap中找到

<ImageView
        android:id="@+id/imageView2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@mipmap/imagename" />

要在Imageview中显示原始图像大小,请写下以下内容。
android:layout\u height=“wrap\u content”
android:adjustViewBounds=“true”
完成这项工作。不需要设置ScaleType

<ImageView
     android:id="@+id/iv_QuestionImage"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_margin="10dp"
     android:adjustViewBounds="true"
     android:src="@drawable/ic_app_icon_512"
     android:visibility="gone"
     app:layout_constraintLeft_toLeftOf="parent"
     app:layout_constraintRight_toRightOf="parent"
     app:layout_constraintTop_toTopOf="parent" />


问题不在于ImageView,您应该提供整个.xml文档,可能是一些重量问题或其他问题。如果图像需要在范围内,为什么不设置imageview的高度和宽度以及缩放类型fitXY?@DarkoRodic我用完整的XML编辑了原始帖子-我没有使用权重。为什么不使用RelativeLayout容器-以便可以相对于imageview的位置指定textview位置?使用match_parent而不是wrap_内容,并将图像的缩放类型更改为fitXYadjustViewBounds,以保存实际上不需要的DAYscaleType。这项工作由我来完成。但是有人能解释为什么会发生这个问题吗?@AjithMemana看到文档:经过几个小时的挣扎。。非常感谢。
<ImageView
     android:id="@+id/iv_QuestionImage"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_margin="10dp"
     android:adjustViewBounds="true"
     android:src="@drawable/ic_app_icon_512"
     android:visibility="gone"
     app:layout_constraintLeft_toLeftOf="parent"
     app:layout_constraintRight_toRightOf="parent"
     app:layout_constraintTop_toTopOf="parent" />