2015-07-03 102 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。