2015-07-03 101 views
1

我有一個適配器,它將圖像加載到ImageView和Picasso,直到這裏一切正常。 問題是我被自己處理方向的變化:Android Picasso處理方向已更改

android:configChanges="orientation|keyboardHidden|screenSize" 

,我不能讓畢加索重新加載圖像,並正確地安裝它的ImageView的方向改變後。

if (imageUrlString == null) { 
     Picasso.with(context).load(R.drawable.image_adega).fit().centerCrop() 
       .into(headerHolder.img_store); 

    } else { 

     Picasso.with(context).load(imageUrlString).fit().into(headerHolder.img_store); 
    } 

而且在我的活動:

@Override 
    public void onConfigurationChanged(Configuration newConfig) { 
     super.onConfigurationChanged(newConfig); 
     if (adapter != null) { 
      adapter.reloadPicasso(getActivity()); 
     } 
    } 

XML:

<ImageView 
    android:id="@+id/img_store" 
    android:layout_width="match_parent" 
    android:layout_height="250dp" 
    android:layout_centerHorizontal="true" 
    android:adjustViewBounds="false"/> 

感謝

+0

你能發佈你的佈局XML文件的樣子嗎? – bodagetta

+0

添加了xml片段 – firetrap

+1

在方向更改後,您不需要強制重新加載圖像。圖像大小由ImageView控制。嘗試將android:scaleType =「centerCrop」添加到您的佈局XML – bodagetta

回答

2

你需要改變你的佈局文件來指定縮放類型。

添加

android:scaleType="centerCrop" 

到您的佈局XML文件,然後當設備被旋轉的ImageView將自動縮放圖像。您不需要使用Picasso手動重新加載ImageView。