Sergio76
Sergio76

Reputation: 3986

ImageView without scaling

I have a ListView that shows rows

This is the xml:

 ...
  <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="@color/white"
        android:orientation="vertical" >

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight=".30">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/face"
                android:scaleType="centerCrop" />
        </FrameLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight=".70"
            android:background="@color/white"
            android:padding="4dp" >

            // Other views...

        </LinearLayout>
    </LinearLayout>
    …

and get this result:

enter image description here

this is the original image

enter image description here

need is the image without scaling, just like this:

enter image description here

I am using android: ScaleType = "centerCrop" I tested with android: adjustViewBounds = "true" and many other parameters, but never successfully

Ideas?

thanks in advance

Upvotes: 3

Views: 2139

Answers (4)

jobpav1984
jobpav1984

Reputation: 11

I think, your problem is inserted weights in LinearLayout and FrameLayout. Please use RelativeLayout without weight. System can not crop your picture because system can not measure ImageView and can not compare him with your picture. In sum system thinks "This is picture and ImageView equal". I have done so :

 <RelativeLayout        
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:padding="5dp">

      <ImageView 
          android:id="@+id/image"
          android:layout_height="50dp"
          android:layout_width="match_parent"
          android:src="@drawable/photo"
          android:scaleType="centerCrop"
          android:contentDescription="@string/app_name"
          android:layout_alignParentTop="true"
          />
      <TextView android:layout_height="150dp"
          android:layout_width="match_parent"
          android:text="@string/text"
          android:layout_below="@id/image"
          android:maxLength="350"
          android:layout_marginTop="5dp"/>

</RelativeLayout>

Upvotes: 0

Sankar V
Sankar V

Reputation: 4863

Set your image to android:src instead of android:background.

<ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@drawable/face"
                android:scaleType="centerCrop" />

All views can take a background image

The src to an ImageView has additional features:

  • different scaling types
  • adjustViewBounds for setting bounds to match image dimensions
  • some transformations such as alpha-setting

And more that you may find in the docs.

Upvotes: 3

Anup Cowkur
Anup Cowkur

Reputation: 20553

You can use android:src instead of android:background to set your drawable. Something like:

<ImageView  android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/face"
            android:scaleType="centerCrop" />

Also, Why not just crop the image using an image editor software like photoshop and use that image instead? Dynamically scaling and manipulating images should be avoided to prevent heavy use of system resources as far as possible.

Upvotes: 0

JiTHiN
JiTHiN

Reputation: 6588

Change android:background="@drawable/face" to android:src="@drawable/face" Scale type will only work forandroid:src

Upvotes: 0

Related Questions