我有一个使用BitmapFragment(下面)的Android FragmentPagerAdapter,效果很好。现在我正试图动态切换图像。我试过更改ImageView但没有任何变化。我已经尝试使用FragmentTransaction.replace交换它,但我得到一个无效的参数异常。我知道getImageViewAtPage()工作,“位图”是一个有效的位图。
谢谢!
private class BitmapFragment extends Fragment {
private int mPosition = 0;
private ImageView mImageView;
private BitmapFragment(int num){
super();
mPosition = num;
}
public ImageView getImageView(){
return mImageView;
}
/**
* The Fragment's UI is just a Bitmap
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_bitmap, container, false);
try{
mImageView = (ImageView) v.findViewById(R.id.bitmap);
mImageView.setImageBitmap(bitmap);
}
catch(Exception e){
e.printStackTrace();
}
return v;
}
}
private void changeImage() {
/*
BitmapFragment bf = new BitmapFragment(mCurrentPageIndex);
FragmentTransaction ft = mReaderViewHandler.getSupportFragmentManager().beginTransaction();
ft.replace(R.layout.fragment_bitmap, bf);
ft.commit();
*/
ImageView v = getImageViewAtPage(mCurrentPageIndex);
try {
v.setImageBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
v.invalidate();
}
答案 0 :(得分:0)
请尝试在mImageView.setImageBitmap()
方法中changeImage()
而不是使用v = getImageViewAtPage
并执行v.setImageBitmap()
。