[英]Android Fit image to full width using Picasso library
我正在使用Picasso库来加载图像并且其工作正常但在使用此库之后图像不适合布局。 如果我将图像直接设置到ImageView
那么图像将适合布局。是否有任何选项可以在毕加索中传递方法以使图像适合布局
Picasso.with(getContext())
.load(R.drawable.dddd).
.into(lavdateimageView);
即使我试图调用以下方法但没有用
fit()
, croptinside()
等
XML文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:background="#ffffff"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#ffffff"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="260dp"
android:layout_marginBottom="3dp"
android:id="@+id/lavdate_image"
android:orientation="vertical"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lavdateimageView" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text to"
android:padding="3dp"
android:background="#ffffff"
android:textColor="#000000"
android:layout_margin="3dp"
android:textStyle="bold"
android:id="@+id/sss" />
</LinearLayout>
</ScrollView>
</LinearLayout>
我也有同样的问题,所以我尝试了它工作正常
Picasso.get()
.load(IMAGE_URL)
.fit()
.centerCrop()
.into(imageView);
最后我理解了我的错误。 我用android:scaleType="centerCrop"
,现在我的图像适合布局
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:id="@+id/myimageView" />
尝试像这样更改imageview
的属性
<ImageView
android:id="@+id/lavdateimageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
然后
Picasso.with(getContext()).load(R.drawable.dddd)
.fit()
.centerCrop()
.into(lavdateimageView)
<ImageView
android:id="@+id/image"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"/>
myPicassoProvider.get(activity).load(getImageUrl()).into(image);
通过这种方式,您的图像将根据需要设置为宽度,并保持纵横比
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.