我制作的应用程序应该显示完整质量的可缩放图像,如内置的Android图库应用程序。我尝试了一些图书馆,但没有一个像我预测的那样完成了这项工作。其中一些人无法提供完整质量的位图。
其他使用BitmapRegionDecoder
的库运行良好,但无法解码某些图像类型(CMYK,灰度)。
我不知道大多数照片库应用程序如何完美展示所有图像?
答案 0 :(得分:0)
使用此代码:
NAVViewPagerAdapter.java
public ViewPagerAdapter( Context aContext, int[] aImages ) {
this.myContext = aContext;
myImages = aImages;
myInflater = LayoutInflater.from( aContext );
}
@Override
public void destroyItem( ViewGroup aContainer, int aPosition, Object aObject ) {
aContainer.removeView( ( View )aObject );
}
@Override
public int getCount( ) {
return myImages.length;
}
/**
* @param view
* @param position
* @return
*/
@Override
public Object instantiateItem( ViewGroup view, int position ) {
View aView = myInflater.inflate( R.layout.layout_inflate_fullscreen_activity, view, false );
final ImageView aImageView = ( ImageView )aView
.findViewById( R.id.fullscreen_activity_IMG );
aImageView.setImageResource(myImages[position]);
view.addView( aView, 0 );
return aView;
}
@Override
public boolean isViewFromObject( View view, Object object ) {
return view.equals( object );
}
@Override
public void restoreState( Parcelable state, ClassLoader loader ) {
}
@Override
public Parcelable saveState( ) {
return null;
}
}
NAVFullScreenFragment.java
public class NAVFullScreenFragment extends Fragment {
private ViewPager myViewPager;
private int[] myImagesArray = NAVGridViewAdapter.myImages;
private FragmentActivity myActivity;
@Nullable
@Override
public View onCreateView( LayoutInflater aInflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState ) {
View aView = aInflater.inflate( R.layout.screen_fragment_viewpager, container, false );
viewPagerAndWidgetInitialize( aView );
return aView;
}
/**
* ViewPager & Widget Initialization
*
* @param aView
*/
private void viewPagerAndWidgetInitialize(View aView) {
myActivity = getActivity();
myViewPager = ( ViewPager )aView.findViewById( R.id.screen_fragment_viewpager_pager );
CircleIndicator aIndicator = ( CircleIndicator )aView.findViewById( R.id.indicator );
Bundle aBundle = getArguments();
myViewPager.setAdapter( new NAVViewPagerAdapter(myActivity, myImagesArray));
if( aBundle != null ) {
int aPosition = aBundle.getInt( "id" );
// Set the images into ViewPager
NAVViewPagerAdapter aPageradapter = new NAVViewPagerAdapter( myActivity, myImagesArray );
myViewPager.setAdapter(aPageradapter);
aIndicator.setViewPager(myViewPager);
// Show images following the position
myViewPager.setCurrentItem(aPosition);
}
}