2017-01-14 26 views
-5

我提出它采用图片来自服务器的图像滑块,我能得到的所有图像JSONarrayinstantiateItem方法需要的图片在int[]如何使图像滑块在Android中使用图片来自URL

imageView.setImageResource(img_resource[position]); 

我该怎么办?

+0

尝试张贴问题之前,谷歌搜索。欢迎来到SO btw。 –

+0

'imageView.setImageResource','imageView.setImageDrawable','imageView.setBacgroundDrawable','imageView.setImageBitmap'你知道所有这些方法吗? –

+0

或者您是否听说过Glide或Picasso图书馆?或者你是否知道,从服务器上处理不正确的图像会导致你出现OOM错误? –

回答

0

你应该看看这个库来实现图像滑块

Github Link

它非常使用

布局

插入XML标签

<com.daimajia.slider.library.SliderLayout 
     android:id="@+id/slider" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
/> 

发现它在你的活动

SliderLayout sliderShow = (SliderLayout) findViewById(R.id.slider); 

申报幻灯片,你可以尝试多达想

您可以添加一个循环,在滑块添加多张图片

TextSliderView textSliderView = new TextSliderView(this); 
textSliderView 
    .description(title) 
    .image(image link); 

然后将其添加到滑块 sliderShow.addSlider(textSliderView) ;

要使用添加到您的应用级这个的build.gradle

dependencies { 
    compile "com.android.support:support-v4:+" 
    compile 'com.squareup.picasso:picasso:2.3.2' 
    compile 'com.nineoldandroids:library:2.4.0' 
    compile 'com.daimajia.slider:library:[email protected]' 

}