Image View not Wrapping Contents

后端 未结 3 589
再見小時候
再見小時候 2021-01-31 01:24

I\'ve got an ImageView wrapping this image:



        
相关标签:
3条回答
  • 2021-01-31 01:50

    if you try to add the large size image for eg let say 4~6 mb and you are using the drawable,then you would get the error like->java.lang.RuntimeException: Canvas: trying to draw too large(537528960bytes) bitmap

    For java do this in your android studio, but the concept remains same for others also,do this to insert the image in your app in the background, applicable for both large and small size images.

    Basically move your image in the (hi-res) drawable to drawable-xxhdpi which would be finded by going in the app->res->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" />
    
    0 讨论(0)
  • 2021-01-31 02:07

    To display original image size in Imageview write down following. android:layout_height="wrap_content" and android:adjustViewBounds="true" do the job. No need to set 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" />
    
    0 讨论(0)
  • 2021-01-31 02:11

    Add the following fields to ImageView:

    android:scaleType="fitXY"
    android:adjustViewBounds="true"
    
    0 讨论(0)
提交回复
热议问题