wei*_*o16 5 android android-image android-imageview picasso android-layoutparams
我有一个ImageView以编程方式创建的,并使用Picasso加载图像.ImageView的高度和宽度设置为WRAP_CONTENT.图像非常大,所以我想使用Picasso的.fit().centerCrop()方法来节省内存.但是,当我添加方法时,图像不会显示,我认为它必须是因为WRAP_CONTENT.这是我的代码:
ImageView iv = new ImageView(getContext());
RelativeLayout.LayoutParams centerParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
iv.setLayoutParams(centerParams);
Picasso.with(context)load(path).fit().centerCrop().into(iv); //if I remove .fit().centerCrop(), the images load just fine
Run Code Online (Sandbox Code Playgroud)
我能找到的唯一信息是GitHub关于它的这个问题 - 虽然问题说它在v2.4中已经关闭,但有些人评论说他们在v2.5中遇到过它.(我也使用v2.5)
编辑:根据Angela的建议,这就是我现在使用的内容:
ImageView iv = new ImageView(getContext());
RelativeLayout.LayoutParams centerParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(350));
centerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
iv.setLayoutParams(centerParams);
iv.setAdjustViewBounds(true);
iv.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
Picasso.with(getContext()).load(path).fit().into(iv);
Run Code Online (Sandbox Code Playgroud)
现在显示图像,但它们没有正确缩放,宽高比会以某种方式改变.关于如何保持纵横比同时仍允许毕加索进行测量的任何想法.fit()?
我也遇到了这个问题.这就是我做的......
Picasso
.with(context)
.load(path)
.fit()
.into(iv);
Run Code Online (Sandbox Code Playgroud)
在xml文件中,尝试包括scaleType,adjustViewBounds和layout_gravity,例如:
<ImageView
android:id="@+id/img_movie"
android:layout_width="match_parent"
android:layout_height="350dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!:)
| 归档时间: |
|
| 查看次数: |
4594 次 |
| 最近记录: |