我必须在我的项目中使用小于 15 的 sdk 版本,因为我的字体在使用 sdk:15 时会崩溃,这是一个屏幕截图:
但是当我使用较低的 sdk 版本时,我ViewPager
在其他活动中的速度会变慢,这是我的ViewPager
活动代码:
public class MainActivity extends FragmentActivity {
private boolean async = false;
private class MyFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle b = getArguments();
final int position = b.getInt("position");
View v = inflater.inflate(R.layout.fragment, null);
final ImageView img = (ImageView) v.findViewById(R.id.img);
if (!async) {
Bitmap bmp = BitmapFactory.decodeFile("/mnt/sdcard/image/"
+ shortcuts[position] + ".jpg");
img.setImageBitmap(bmp);
async = true;
} else {
AsyncTask<Integer, Integer, Integer> task = new AsyncTask<Integer, Integer, Integer>() {
Bitmap bmp;
@Override
protected void onProgressUpdate(Integer... values) {
img.setImageBitmap(bmp);
super.onProgressUpdate(values);
}
@Override
protected Integer doInBackground(Integer... params) {
bmp = BitmapFactory.decodeFile("/mnt/sdcard/image/"
+ shortcuts[params[0]] + ".jpg");
publishProgress();
return null;
}
};
task.execute(position);
}
return v;
}
}
private class MyAdapter extends FragmentPagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment f = new MyFragment();
Bundle b = new Bundle();
b.putInt("position", position);
f.setArguments(b);
return f;
}
@Override
public int getCount() {
return shortcuts.length;
}
}
private int[] shortcuts = new int[] { 1, 2, 3, 4, 5, 6 };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ViewPager pager = (ViewPager) findViewById(R.id.pager);
FragmentManager fm = getSupportFragmentManager();
MyAdapter pagerAdapter = new MyAdapter(fm);
pager.setAdapter(pagerAdapter);
pager.setOffscreenPageLimit(3);
}
}
当我设置android:targetSdkVersion="15"
它运行良好,但将其设置为 10 时结果非常慢。更改页面时结果很慢,我该如何解决?我的 android-support-v4.jar 文件是 385,685 字节。