I have a listview which look like this:

![enter image description here](https://i.stack.imgur.com/RhW5p.png)

but it is after giving hardcoded hight and width in xml.
This is my XML for listview adaptor:

```
<LinearLayout 
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="3"    
    android:orientation="horizontal">

<ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="14dp"
    android:layout_marginTop="4dp"
    android:layout_marginRight="3dp"
    android:layout_marginBottom="4dp"
    android:adjustViewBounds="true"
    android:contentDescription="@string/descr_image"
    android:scaleType="centerCrop" />

</LinearLayout>

 <LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="7"
    android:weightSum="7"
 android:orientation="horizontal" 
 > 

<TextView
    android:id="@+id/text"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="5"
    android:layout_gravity="left|center"
    android:gravity="center|left"
    android:layout_marginLeft="20dip"
    android:textSize="18sp" 

   />

<ImageView 
    android:id="@+id/arrow"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:layout_gravity="right|center"
    android:src="@drawable/bluearrowmap"
    android:layout_marginRight="10dp"

    />

</LinearLayout>  

```

I am giving First image 2% width but the problem is that now how can i give height to that imageview same like it will take width from difference devices.Because i want this image to be a square just like it is in picture.
i have tried this piece of code in my adaptor class

```
        ViewTreeObserver vto = holder.image.getViewTreeObserver();
            vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
                public boolean onPreDraw() {
                    holder.image.getViewTreeObserver().removeOnPreDrawListener(this);
                    int finalHeight = holder.image.getMeasuredHeight();
                    int finalWidth = holder.image.getMeasuredWidth();

                    holder.image.getLayoutParams().height=finalWidth;

                    return true;
                }
            }); 

```

i am writting this code in my getview of adaptor class.it works fine sometime but sometime it needs a scroll down to set the height of imagview according to width.
Can someone plz help? i have tried every solution on internet but all in vain.
thanks.