我正在制作广告横幅,我想在横幅布局中4秒钟后翻转图像,因此我正在使用Viewflipper。我想显示从Web服务获取的图像,因此我正在从Web服务解析图像并创建它的列表,但是当使用for循环将该列表项传递给viewflipper时,它仅显示一个图像,并且列表包含两个项。谁能帮助我找出我的错误。
查看鳍状肢方法..
public void flipperImages(String image){
ImageView imageView = new ImageView(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
imageView.setLayoutParams(params);
Log.e("image_product", image);
if (image.equals("0")) {
imageView.setBackgroundResource(R.drawable.placeholder_rec);
} else {
Picasso.with(this).load(image).error(R.drawable.placeholder_rec).placeholder(R.drawable.placeholder_rec).into(imageView);
}
v_flipper.addView(imageView);
v_flipper.setFlipInterval(4000);
v_flipper.setAutoStart(true);
v_flipper.setInAnimation(this, android.R.anim.slide_in_left);
v_flipper.setOutAnimation(this, android.R.anim.slide_out_right);
}
Api调用和flipperImages()调用...
private void categoryListApi() {
if (NetworkUtil.isNetworkAvailable(this)) {
loader.setVisibility(View.VISIBLE);
Api api = ApiClient.getClient().create( Api.class );
Call<ResponseBody> call = api.getCatList("1");
call.enqueue( new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
try {
loader.setVisibility(View.GONE);
String JSON_STRING = response.body().string();
JSONObject jsonRootObject = new JSONObject( JSON_STRING );
String status = jsonRootObject.getString( "status" );
String message = jsonRootObject.getString( "message" );
if (status.equals( "1" ))
{
JSONArray jsonArrayBanner = jsonRootObject.getJSONArray( "banner" );
for (int i=0; i<jsonArrayBanner.length(); i++)
{
JSONObject objectData = jsonArrayBanner.getJSONObject(i);
String bannerUrl = objectData.getString( "img" );
bannerList.add( bannerUrl );
}
Log.e("banner", bannerList.toString());
for (int i=0; i<bannerList.size(); i++)
{
flipperImages(bannerList.get(i));
}
} else {
loader.setVisibility(View.GONE);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
Log.e( "ErrorProfile" , e.getMessage());
loader.setVisibility(View.GONE);
popUpDialog();
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
loader.setVisibility(View.GONE);
//Toast.makeText( getApplicationContext(), "Failed " + t, Toast.LENGTH_LONG ).show();
}
} );
}
else {
popUpDialogInternet();
}
}