Skip to content Skip to sidebar Skip to footer

Android - Imageview From Url Won't Fill_parent In Listview

I have a JSON, I am parsing the JSON. It results with text and an image in a listview. Everything works fine except one thing. I am trying to get the ImageView to fill_parent as wi

Solution 1:

Try with this:

     <ImageView
        android:id="@+id/iv_flag"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"/>

From the doc:

android:adjustViewBounds
Set this totrueif you want the ImageView to adjust its bounds topreserve the aspect ratio of its drawable.

Try changing scaleType="fitCenter" for "centerInside"

if that doesn't work, try this custom ImageView.

publicclassAspectRatioImageViewextendsImageView {

publicAspectRatioImageView(Context context) {
    super(context);
}

publicAspectRatioImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

publicAspectRatioImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@OverrideprotectedvoidonMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    intwidth= MeasureSpec.getSize(widthMeasureSpec);
    intheight= width * getDrawable().getIntrinsicHeight() / getDrawable().getIntrinsicWidth();
    setMeasuredDimension(width, height);
}

}

and replace ImageView for

     <com.package.AspectRatioImageView
    android:id="@+id/iv_flag"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter"/>

Solution 2:

Can You try add this attribute to imageView

android:scaleType="fitXY"

It will look like

 <ImageView
        android:id="@+id/iv_flag"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:src="@drawable/abs__ab_bottom_solid_light_holo"

        android:scaleType="fitXY"

        android:layout_below="@+id/byline" />

Post a Comment for "Android - Imageview From Url Won't Fill_parent In Listview"