我在github上使用CaruselView项目,我想动态更改PageCount
,但我没有找到任何相关信息。
以下是代码示例:
public class SampleCarouselViewActivity extends AppCompatActivity {
CarouselView carouselView;
int[] sampleImages = {R.drawable.image_1, R.drawable.image_2, R.drawable.image_3, R.drawable.image_4, R.drawable.image_5};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_carousel_view);
carouselView = (CarouselView) findViewById(R.id.carouselView);
carouselView.setPageCount(sampleImages.length);
carouselView.setImageListener(imageListener);
}
ImageListener imageListener = new ImageListener() {
@Override
public void setImageForPosition(int position, ImageView imageView) {
imageView.setImageResource(sampleImages[position]);
}
};
}
可能会动态重置计数并设置新计数?有什么想法吗?
答案 0 :(得分:0)
您必须在更改尺寸之前移除旋转木马的父级,而不必将其重新分配给旋转木马。
if (carouselView != null) {
parentView = carouselView.getParent();
if (parentView != null && parentView instanceof ViewGroup) {
ViewGroup g = (ViewGroup) parentView;
g.removeView(carouselView);
}
}
carouselView.setPageCount(newSize);
if (parentView != null && parentView instanceof ViewGroup) {
ViewGroup g = (ViewGroup) parentView;
g.addView(carouselView);
}