-2
我有一個ViewFlipper的android活動。 它從網址中選取圖片並顯示在佈局中。 它應該讓所有的圖像生動。 但是,它只會動畫第一個url圖像,並且會不斷重複。 它不顯示其他圖像。 下面是代碼:Android ViewFlipper只動畫第一個URL圖像
公共類DynamicViewFlipper延伸活動{
/**
* List of Image URL that will populate the ViewFlipper
*/
private List<String> imageURLs = Arrays.asList(new String[] {
"http://example.com/image1.jpg",
"http://example.com/image2.jpg",
"http://example.com/image3.jpg",
"http://example.com/image4.jpg"});
private int index = 0;
private TextView mTextView;
private ViewFlipper mViewFlipper;
private Button mNextButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_flipper);
mTextView = (TextView) findViewById(R.id.title);
mViewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper);
ImageView image = new ImageView(getApplicationContext());
UrlImageViewHelper.setUrlDrawable(image, getNextImage(), R.drawable.loading);
mTextView.setText("Showing: " + index);
mViewFlipper.addView(image);
mViewFlipper.showNext();
mViewFlipper.setAutoStart(true);
mViewFlipper.setFlipInterval(2000);
mViewFlipper.startFlipping();
mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.slide_in_left));
mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.slide_out_right));
}
protected String getNextImage() {
if (index == imageURLs.size())
index = 0;
return imageURLs.get(index++);
}
}
*簡單ViewAnimator會之間動畫**兩個或更多的視圖已被添加到它。*** vs'mViewFlipper.addView(image)'並且僅此而已... – Selvin