-4

how can I crop or resize one image? My application will be receive images from one server, and I don't know nothing about that images, I don't know size, aspect ration or dimension. And all of that images will be show on my list, if you can see I have one image as square and one as rectangle. So know anyone how can I crop that images or how to make the images view fix? Because I need to fill all that images at to look like the same size, something like that. More exactly, if I've receive one image as 2000x2000 and one as 1024x300 I want to convert that images to have both one resolution something like 300x200 on viewimage.

Here is my XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:padding="0dp">


    <RelativeLayout
        android:id="@+id/layout_item_car"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0">

        <ImageView
            android:id="@+id/img_tail"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:gravity="fill"
            android:scaleType="fitStart"/>

        <TextView
            android:id="@+id/tail_location"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_horizontal"
            android:text="@string/color"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/holo_orange_light"
            android:textSize="25dp"
            android:textStyle="bold"
            tools:targetApi="ice_cream_sandwich"/>

        <TextView
            android:id="@+id/tail_description"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="@string/model"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/holo_orange_light"
            android:textStyle="normal"
            tools:targetApi="ice_cream_sandwich"/>


    </RelativeLayout>

</LinearLayout>

If anyone know how can I solve that problem pleas show me. :)

J.D
  • 77
  • 1
  • 7

1 Answers1

1

Dont' use wrap or match parent. You must the a fixed height for your row container (for example: 300dp). Then use: android:scaleType="centerCrop" in your ImageView. That way, every single row will have the same height and crop.

Mariano Zorrilla
  • 7,165
  • 2
  • 34
  • 52