我有一个显示GPUImageViews的ViewPager。为每个页面创建实例时,一切看起来都很棒。当我尝试向后滑动以加载上一页时出现问题。这是我的onCreateView代码。
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//I store my previous pages in an imageArray variable to prevent application from rendering image over and over again.
temp = imageArray[this.index]; //temp is a GPUImageView; assume initialized
if (temp.getParent() != null) {
((ViewGroup) temp.getParent()).removeView(temp);
}
temp.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
return temp;
}
当我添加removeView()
时,视图寻呼机始终返回黑屏。我尝试取消removeView()
,但它总是给我错误“子视图已存在父级...首先删除父视图。”
编辑: 更具体地说,我添加了我的onCreate(),init()和renderImage()函数。顺便说一句,这是一个片段,我的PagerAdapter我正在使用FragmentPagerAdapter
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivity().findViewById(R.id.saveBtn).setOnClickListener(this);
this.init();
this.renderImage();
}
private void init() {
temp = new GPUImageView(getActivity());
this.img = new GPUImageView(getActivity()); //the original image
this.img.setImage(imgUri);
}
private void renderImage() {
temp = this.img;
temp.setFilter(Filter.setFilter(getActivity(), this.filterPosition));
temp.requestRender();
imageArray[this.filterPosition] = temp;
}
我尝试调试以查看我的应用程序是如何工作的......似乎在创建新实例时,将始终调用onCreate(),然后调用onCreateView()。基于此guide的生命周期,我认为只会重复调用onCreateView()。