首页 新闻 会员 周边 捐助

安卓项目异常 The specified child already has a parent. You must call removeView()

0
悬赏园豆:20 [已关闭问题] 关闭于 2016-05-17 18:07

我在先获取ImageView对象,后执行ImageSwitcher.setFactory(new ViewSwitcher.ViewFactory(){});就会出现上面异常。反之就正常,请问产生错误原理是什么。 注释地方为错误处

 

private ImageSwitcher switcher;
private ImageView imageView;
private int foot = 0;
private int[] imgRes = new int[]{R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
inintView();
switcher.setFactory(new ViewSwitcher.ViewFactory() { // !!!!!!!!!!!!!!!!!!!
@Override
public View makeView() {
imageView.setBackgroundColor(0xFFFFFFFF);
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setLayoutParams(new ImageSwitcher.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
return imageView;
}

});

switcher.setImageResource(imgRes[++foot]);
switcher.setInAnimation(this, android.R.anim.fade_in);
switcher.setOutAnimation(this, android.R.anim.fade_out);
}

void inintView() {
switcher = (ImageSwitcher) findViewById(R.id.imgView);
findViewById(R.id.btnPrevious).setOnClickListener(new OnClickListenerImp());
findViewById(R.id.btnNext).setOnClickListener(new OnClickListenerImp());
imageView = new ImageView(MainActivity.this); // !!!!!!!!!!!!!!!!!!!

}

 

 

ankkaya的主页 ankkaya | 菜鸟二级 | 园豆:202
提问于:2016-04-07 18:14
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册