2016-09-07 39 views
0

我想插入一个图像到一个ImageView,它被用作背景。这个背景是在一个RecyclerView中。当它被第一次加载,它看起来像这样:毕加索中心适合和适合会得到不同的结果

enter image description here

但是当我滚动到另一项目和向后滚动,它看起来像这样(它应该永远是这样):

enter image description here

在这里,我添加图像:

public void onBindViewHolder(StoryViewHolder holder, int position) { 
    holder.cardView.setMinimumHeight(height/3); 
    holder.layout.setMinimumHeight((int) ((float) width/4)); 
    //set image 

    Picasso.with(activity).load(MainPostAdapter.URL + 140 + ".png"). 
      transform(new BlurTransform(holder.background.getContext())).fit().centerCrop().into(holder.background); 
    holder.background.setAlpha(0.25f); 
} 

而且这是图片本身:

<ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/story_view_background"/> 

问题是什么?

编辑: 整个XML(它不显示所有的代码这里也是引擎收录:http://pastebin.com/8rJvSx7V):

<?xml version="1.0" encoding="utf-8"?> 

<ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/story_view_background"/> 
    <RelativeLayout 
     android:id="@+id/story_view_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingTop="50px"> 
     <ImageView 
      android:id="@+id/story_view_image" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 
     <TextView 
      android:id="@+id/story_view_text" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="13sp" 
      android:layout_below="@+id/story_view_image" 
      android:paddingBottom="8dp" 
      android:paddingTop="8dp" 
      android:gravity="center_horizontal" 
      android:layout_alignParentBottom="true"/> 
    </RelativeLayout> 
</FrameLayout> 

+0

显示更多XML,问题。你的'ImageView'可能应该有不同的宽度和高度设置 – snachmsm

+0

@snachmsm我已经更新了它。 – user6586661

回答

1

尝试设置android:layout_height="150dp"为您的CardView(不要使用px!)。其孩子FrameLayout是unnecesarry(CardView延伸FrameLayout并设置相同的属性设置),将其删除。

它不是那么好写的,你所有的View■找身高match_parent集,除了图像和文本的意见...您的项目可能正试图适应RecyclerView高度在这种情况下(“全屏幕”),并没有测量第一时间图像(毕加索异步下载,视图已经测量时设置图像)。但是当你再次膨胀你的View(滚动和回收)时,新的列表项目的测量方式会有所不同,因为毕加索会在“运行时”插入图像,不需要异步提取(缓存)