質問

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?

役に立ちましたか?

解決

Try with:

android:scaleType="centerCrop" 

in the xml

他のヒント

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" 

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top