毕加索不会将可绘制图像加载到 ImageView 中
Picasso doesn't load drawable image into ImageView
Picasso
无法将图像 drawable
加载到 ImageView
,我尝试更改 ImageView
的宽度和高度,调整图像大小,加载它如果没有 fit()
、resize()
或 center()
,图像仍然不可见。我在整个项目中使用 Picasso
,到处都工作正常,但它没有给出结果。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainFullFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/mainThemeBlack"
tools:context=".MainTabsActivity">
<RelativeLayout
android:id="@+id/rlSynchroView"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:background="@color/bottom_sheet_blue">
<TextView
android:id="@+id/tvSynchroLast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:layout_marginEnd="10dp"
android:textColor="@color/mdtp_white"
android:text="Last synchro: 10:38"/>
<ImageView
android:id="@+id/ivSynchroIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvSynchroLast"
android:elevation="5dp"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/listFullView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:dividerHeight="10.0sp"
android:layout_above="@id/rlSynchroView"
android:background="?android:attr/selectableItemBackground"
android:divider="@color/mainThemeBlack"
android:paddingBottom="70dp"
android:clipToPadding="false">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
方法调用:
Picasso.get().load(R.drawable.refresh_icon)
.resize(10, 10)
.into(refreshIV);
我在 onViewCreated()
中调用它,我也尝试用不同的值调整它的大小。
我想实现带有刷新图标的可点击底部栏(以及有关上次同步时间的信息),以便在 onClick
方法
中与服务同步数据
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.list_full, container, false);
refreshIV = mView.findViewById(R.id.ivSynchroIcon);
mobileArray = new ArrayList<IssuePOJO>();
dbStats.open();
generateList();
mView = view;
return mView;
}
Picasso 遇到了这个问题,你应该尝试在你的可绘制对象中使用占位符
Picasso.get().load(R.drawable.refresh_icon)
.resize(10, 10)
.placeholder(R.drawable.refresh_icon)
.into(refreshIV);
您将其加载到错误的 Imageview 中。像这样更改您的代码
Picasso.get().load(R.drawable.refresh_icon).into(ivSynchroIcon);
如果你想看看哪里出了问题,只需像这样添加 Picasso 回调
Picasso.get()
.load(R.drawable.refresh_icon)
.into(ivSynchroIcon, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError(Exception e) {
}
})
试试这条线
Picasso.with(context).load(url).resize(10, 10).into(refreshIV);
由于您的资源中已有可绘制对象 (refresh_icon),您可以将其直接放入布局中。
<ImageView
android:id="@+id/ivSynchroIcon"
android:layout_width="70dp"
android:layout_height="70dp"
android:padding="10dp"
android:layout_below="@+id/tvSynchroLast"
android:src="@drawable/refresh_icon"
android:elevation="5dp"/>
如果您仍然想使用 Picasso,请尝试在布局检查器中检查 ivSynchroIcon 元素。
因此,您可以看到图像视图的放置位置以及测量值。
在 Android 工作室 Tools -> Layout Inspector
Picasso 语法看起来正确,但 onCreateView 方法逻辑看起来不正确
请尝试使用以下代码:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.list_full, container, false);
refreshIV = mView.findViewById(R.id.ivSynchroIcon);
mobileArray = new ArrayList<IssuePOJO>();
dbStats.open();
generateList();
//mView = view;//please comment this one and try
return mView;
}
Picasso
无法将图像 drawable
加载到 ImageView
,我尝试更改 ImageView
的宽度和高度,调整图像大小,加载它如果没有 fit()
、resize()
或 center()
,图像仍然不可见。我在整个项目中使用 Picasso
,到处都工作正常,但它没有给出结果。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainFullFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/mainThemeBlack"
tools:context=".MainTabsActivity">
<RelativeLayout
android:id="@+id/rlSynchroView"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:background="@color/bottom_sheet_blue">
<TextView
android:id="@+id/tvSynchroLast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:layout_marginEnd="10dp"
android:textColor="@color/mdtp_white"
android:text="Last synchro: 10:38"/>
<ImageView
android:id="@+id/ivSynchroIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvSynchroLast"
android:elevation="5dp"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/listFullView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:dividerHeight="10.0sp"
android:layout_above="@id/rlSynchroView"
android:background="?android:attr/selectableItemBackground"
android:divider="@color/mainThemeBlack"
android:paddingBottom="70dp"
android:clipToPadding="false">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
方法调用:
Picasso.get().load(R.drawable.refresh_icon)
.resize(10, 10)
.into(refreshIV);
我在 onViewCreated()
中调用它,我也尝试用不同的值调整它的大小。
我想实现带有刷新图标的可点击底部栏(以及有关上次同步时间的信息),以便在 onClick
方法
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.list_full, container, false);
refreshIV = mView.findViewById(R.id.ivSynchroIcon);
mobileArray = new ArrayList<IssuePOJO>();
dbStats.open();
generateList();
mView = view;
return mView;
}
Picasso 遇到了这个问题,你应该尝试在你的可绘制对象中使用占位符
Picasso.get().load(R.drawable.refresh_icon)
.resize(10, 10)
.placeholder(R.drawable.refresh_icon)
.into(refreshIV);
您将其加载到错误的 Imageview 中。像这样更改您的代码
Picasso.get().load(R.drawable.refresh_icon).into(ivSynchroIcon);
如果你想看看哪里出了问题,只需像这样添加 Picasso 回调
Picasso.get()
.load(R.drawable.refresh_icon)
.into(ivSynchroIcon, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError(Exception e) {
}
})
试试这条线
Picasso.with(context).load(url).resize(10, 10).into(refreshIV);
由于您的资源中已有可绘制对象 (refresh_icon),您可以将其直接放入布局中。
<ImageView
android:id="@+id/ivSynchroIcon"
android:layout_width="70dp"
android:layout_height="70dp"
android:padding="10dp"
android:layout_below="@+id/tvSynchroLast"
android:src="@drawable/refresh_icon"
android:elevation="5dp"/>
如果您仍然想使用 Picasso,请尝试在布局检查器中检查 ivSynchroIcon 元素。
因此,您可以看到图像视图的放置位置以及测量值。
在 Android 工作室 Tools -> Layout Inspector
Picasso 语法看起来正确,但 onCreateView 方法逻辑看起来不正确
请尝试使用以下代码:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.list_full, container, false);
refreshIV = mView.findViewById(R.id.ivSynchroIcon);
mobileArray = new ArrayList<IssuePOJO>();
dbStats.open();
generateList();
//mView = view;//please comment this one and try
return mView;
}