Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image View not Wrapping Contents

I've got an ImageView wrapping this image:

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

and right below it, a TextView. Unfortunately, it either pushes it down the view or out of the view depending on the device's screen size.

http://i.imgur.com/CuVFK5P.png

http://i.imgur.com/6wzMebV.jpg

I can "hack" it, but it'd rather not...

<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"/>

like image 585
Tyler Sebastian Avatar asked Jan 18 '14 11:01

Tyler Sebastian


2 Answers

Add the following fields to ImageView:

android:scaleType="fitXY"
android:adjustViewBounds="true"
like image 179
sachin10 Avatar answered Oct 25 '22 07:10

sachin10


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" />
like image 3
Dharmishtha Avatar answered Oct 25 '22 08:10

Dharmishtha