[英]Picasso doesn't load drawable image into ImageView
Picasso
無法將drawable
圖像加載到ImageView
,我試圖更改ImageView
的寬度和高度,調整圖像大小,在使用fit()
resize()
或不使用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;
}
您正在將其加載到錯誤的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) {
}
})
由於您的資源中已經具有可繪制對象(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,請嘗試在Layout Inspector中檢查ivSynchroIcon元素。 因此,您可以看到imageview的放置位置以及尺寸。 在Android Studio 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.with(context).load(url).resize(10, 10).into(refreshIV);
畢加索遇到了這個問題,您應該嘗試在可繪制對象中使用占位符
Picasso.get().load(R.drawable.refresh_icon)
.resize(10, 10)
.placeholder(R.drawable.refresh_icon)
.into(refreshIV);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.