问题
SOLVED Apparently you need to have the fragment drawables in respective drawable-xhdpi etc and not in drawable.
I have coded a ViewPager with three fragments that works flawlessly on LG G2, Sony Xperis S, Nexus4 and 5. But on the Samsung S4 it's impossible to swipe left/right without major lag, we have tested on 4 different S4's with the same resault.
public class ViewPagerMainActivity extends FragmentActivity {
PageIndicator mIndicator;
int mViewPager;
private AutoScrollViewPager viewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.viewpager_layout);
ViewPagerMyPagerAdapter pageAdapter = new ViewPagerMyPagerAdapter(getSupportFragmentManager());
viewPager = (AutoScrollViewPager)findViewById(R.id.pager);
viewPager.setAdapter(pageAdapter);
CirclePageIndicator indicator = (CirclePageIndicator)findViewById(R.id.indicator);
mIndicator = indicator;
indicator.setViewPager(viewPager);
final float density = getResources().getDisplayMetrics().density;
indicator.setBackgroundColor(0xFFFFFFFF);
indicator.setRadius(5 * density);
indicator.setPageColor(0x00000000);
indicator.setFillColor(0xFFFFFFFF);
indicator.setStrokeColor(0xFFDE7900);
indicator.setStrokeWidth(2 * density);
viewPager.setInterval(3000);
viewPager.startAutoScroll();
viewPager.setScrollDurationFactor(12);
viewPager.setCycle(true);
TextView accept = (TextView)findViewById(R.id.textView3);
TextView notNow = (TextView)findViewById(R.id.textView2);
TextView img = (TextView) findViewById(R.id.terms);
img.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent browserIntent = new Intent("android.intent.action.VIEW",
Uri.parse("http://www.123on.com/legal"));
startActivity(browserIntent);
}
});
accept.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ActivityMain.contactPermission = true;
Logging.log("viewPager:"+ActivityMain.contactPermission);
ActivityMain.mActivityMainHandler.saveParams();
if (!ActivityMain.userVerifyFlag){ // user didn't verify phone number
finish();
ActivityMain.verifyPhoneNumber();
} else {
Logging.log("error: with verify flag true without permission true.");
}
}
});
notNow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
@Override
protected void onPause() {
super.onPause();
viewPager.stopAutoScroll();
}
@Override
protected void onResume() {
super.onResume();
viewPager.startAutoScroll();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
and
public class ViewPagerMyPagerAdapter extends FragmentPagerAdapter implements OnPageChangeListener {
private List<Fragment> fragments;
public ViewPagerMyPagerAdapter(FragmentManager fm) {
super(fm);
this.fragments = new ArrayList<Fragment>();
fragments.add(new ViewPagerFragmentOne());
fragments.add(new ViewPagerFragmentTwo());
fragments.add(new ViewPagerFragmentThree());
}
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}
@Override
public int getCount() {
return fragments.size();
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageSelected(int arg0) {
// TODO Auto-generated method stub
}
}
I am starting to suspect that Samsung have some wicked problem in their framwork.
SOLVED
I re-sized the png's in code instead of xml.
Thanks /Gekn
来源:https://stackoverflow.com/questions/23628726/viewpager-really-slow-on-samsung-s4