Android - Fit ImageView to ListView

不问归期 提交于 2019-12-24 04:17:52

问题


I want to fit ImageView inside a ListView row so that it fits to the edge of device's screen.

This is my current layout:

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:smoothScrollbar="true"
        android:id="@android:id/list" />
</RelativeLayout>

In the custom_row.xml:

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/img_item"
        android:adjustViewBounds="true"/>

</RelativeLayout>

I'm using Picasso library to load the image. I've tried using .centerCrop, .centerInside and .fit using Picasso's loader option. No luck.

Picasso settings:

Picasso.with(context) //
        .load(iim.getResized()) //
        .placeholder(R.drawable.placeholder) //
        .error(R.drawable.error)
        .fit().centerInside()
        .into(vh.item_image);

Anyone knows how to deal with this problem?


回答1:


Try with:

android:scaleType="centerCrop" 

in the xml




回答2:


in your program use this .centerCrop()

Picasso.with(context) //
    .load(iim.getResized()) //
    .placeholder(R.drawable.placeholder) //
    .error(R.drawable.error)
    .centerCrop() //thissss
    .into(vh.item_image);

or in your xml:

android:scaleType="centerCrop" 



回答3:


Your ImageView height right now is 0dp. You need to set layout_height. Your width is fine.



来源:https://stackoverflow.com/questions/21277642/android-fit-imageview-to-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!