我在我的應用程序中使用AndroidImageSlider庫作爲圖像滑塊。我加載使用Hashmap
像這樣的圖片:動態圖像滑塊Android
HashMap<String,String> url_maps = new HashMap<String, String>();
url_maps.put("Image 1", "http://example.com/./project_image/example.jpg");
url_maps.put("Image 2", "http://example.com/./project_image/example.jpg");
url_maps.put("Image 3", "http://example.com/./project_image/example.jpg");
for(String name : url_maps.keySet()){
TextSliderView textSliderView = new TextSliderView(this);
// initialize a SliderLayout
textSliderView
.description(name)
.image(url_maps.get(name))
.setScaleType(BaseSliderView.ScaleType.Fit);
//add your extra information
textSliderView.bundle(new Bundle());
textSliderView.getBundle()
.putString("extra",name);
mDemoSlider.addSlider(textSliderView);
}
注:我設置HashMap
的爲每個圖像描述的關鍵。
如何使此滑塊動態?
我想從一個JSON提要看起來像這樣動態加載圖片:它採用了一塊HashMap
{
"Images": [
{
"title": "title",
"Image": "http://example.com/./project_image/example.jpg"
},
{
"title": "Distribution",
"Image": "http://example.com/./project_image/example.jpg"
},
{
"title": "Distribution",
"Image": "http://example.com/./project_image/example.jpg"
}
]
}
能做些什麼或做我需要使用一個替代?如果是,請提出建議。或者我使用不同的圖書館?如果是,請給予參考。 謝謝。
我不能使用哈希映射來做這個嗎? –
這種方法在製作ImageSlider時適用於我,我認爲它也可以使用哈希映射,但從未嘗試過。 –