我正在尝试从 Http 服务器在图像切换器中加载图像。我没有找到像 setImageBitmap 这样的函数。所以我尝试使用 setImageURI() ,但它没有被加载。我试图每 3 秒切换一次图像。这是代码。当我运行代码时,图像没有被加载。应用程序也越来越疯狂。
String arr[]={"http://192.168.1.7/photos/dummy/1.jpg","http://192.168.1.7/photos/dummy/2.jpg","http://192.168.1.7/photos/dummy/3.jpg"}
dailyWear = (ImageSwitcher) getActivity().findViewById(R.id.imageDailyWear);
dailyWear.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
ImageView myView = new ImageView(getActivity());
myView.setScaleType(ImageView.ScaleType.FIT_XY);
myView.setLayoutParams(new ImageSwitcher.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
return myView;
}
});
dailyWear.setInAnimation(AnimationUtils.loadAnimation(getActivity(), android.R.anim.slide_in_left));
dailyWear.setOutAnimation(AnimationUtils.loadAnimation(getActivity(), android.R.anim.slide_out_right));
final Handler handler = new Handler();
final Runnable r = new Runnable() {
int i=0;
public void run() {
weddingWear.setImageURI(Uri.parse(arr[i));
i++;
if (i >= arr.length()-1)
i = 0;
handler.postDelayed(this, 3000);
}
};
handler.postDelayed(r, 1000);