2016-08-21 138 views
-1

我正在開發一個使用firebase的應用程序,該應用程序使用滑動將圖像從firebase存儲讀取到listview中。 你知道什麼是下載圖像到列表視圖項目的最佳方式?從firebase存儲下載圖像

+0

獲得圖像在我們的[零到App通話(HTTPS: //www.youtube.com/watch?v=xAsvwy1-oxE)在Google I/O上使用了Android應用程序中的設置。看看[該應用程序的代碼](https://gist.github.com/puf/f49a1b07e92952b44f2dc36d9af04e3c)開始。 –

+0

謝謝。但我的意思是,在我的應用程序中,我想顯示應用程序附帶的照片,這些照片已存在於Firebase存儲中,而不是用戶上傳的照片。你知道在這種情況下讀取存儲的最佳實踐是什麼? – FVbes

回答

4

如果你正在使用滑動,你可以用它來填充ListView中的ImageView。 Glide有方法into

例如

final ImageView myImageView; 

    Glide 
    .with(myFragment) 
    .load(url) 
    .centerCrop() 
    .placeholder(R.drawable.loading_spinner) 
    .crossFade() 
    .into(myImageView); 
1

我不跟火力地堡貯存熟悉,但我想,當你上傳圖片到這個平臺上,他們給你以訪問該資源的URL。好吧,如果這是正確的,試試這個代碼在你的適配器類爲ListView:

ImageView img = (ImagenView)findViewbyid(R.id.myimageview); 
String url = "http://..."; //Firebase URL to the picture 

Glide.with(yourActivity).load(url).into(img); 

不要忘了修改與滑翔路gradle這個文件。

repositories { 
    mavenCentral() 
} 

dependencies { 
    compile 'com.github.bumptech.glide:glide:3.7.0' 
    compile 'com.android.support:support-v4:19.1.0' 
} 

希望它有幫助!

1

FirebaseUI-Android0.6.0版本包括採取火力地堡StorageReference並加載使用滑翔圖像的能力:

// Reference to an image file in Firebase Storage 
StorageReference storageReference = ...; 

// ImageView in your Activity 
ImageView imageView = ...; 

// Load the image using Glide 
Glide.with(this /* context */) 
     .using(new FirebaseImageLoader()) 
     .load(storageReference) 
     .into(imageView); 

要包含它,只需添加compile 'com.firebaseui:firebase-ui-storage:0.6.0'build.gradle

+0

如何從特定尺寸的Firebase獲取圖片? – ono

+0

我們目前在FirebaseUI中不支持此功能,您需要自行上傳已調整大小的圖像。一個很好的方法是使用Firebase的雲端函數。 –

0

•嘗試添加應用級依賴

dependencies { 
// FirebaseUI Storage only 
compile 'com.firebaseui:firebase-ui-storage:0.6.0' 
} 

•使用下一個代碼從火力存儲

ImageView imageView = findViewById(R.id.image_view); 
Glide.with(context) 
       .using(new FirebaseImageLoader()) 
       .load(pathReference) 
       .into(imageView);