我试图在我的应用程序中,在视图寻呼机的帮助下制作一个小教程。用户从左向右滚动,视图按预期滑入和滑出。我唯一的问题是它很慢。这就是我所做的:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.tutorial);
findViews();
init();
setUserInteraction(); // this works as expected
}
private void init() {
initViewAnimator();
slideInLeft = AnimationUtils.loadAnimation(this, R.anim.slide_in_left);
slideInLeft.setDuration(ANIMATION_DURATION);
slideOutLeft = AnimationUtils.loadAnimation(this, R.anim.slide_out_left);
slideOutLeft.setDuration(ANIMATION_DURATION);
slideInRight = AnimationUtils.loadAnimation(this, R.anim.slide_in_right);
slideInRight.setDuration(ANIMATION_DURATION);
slideOutRight = AnimationUtils.loadAnimation(this, R.anim.slide_out_right);
slideOutRight.setDuration(ANIMATION_DURATION);
}
private void initViewAnimator() {
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.tutorial_page_1, viewAnimator, false);
viewAnimator.addView(view);
view = inflater.inflate(R.layout.tutorial_page_2, viewAnimator, false);
viewAnimator.addView(view);
view = inflater.inflate(R.layout.tutorial_page_3, viewAnimator, false);
viewAnimator.addView(view);
view = inflater.inflate(R.layout.tutorial_page_4, viewAnimator, false);
viewAnimator.addView(view);
}
private void showNext(){
int displayedChild = viewAnimator.getDisplayedChild();
if(displayedChild == NUMBER_OF_FRAMES - 1){
return;
}
viewAnimator.setInAnimation(slideInRight);
viewAnimator.setOutAnimation(slideOutLeft);
viewAnimator.showNext();
onAnimationStarted(displayedChild, ++displayedChild);
}
private void showPrevious(){
int displayedChild = viewAnimator.getDisplayedChild();
if(displayedChild == 0){
return;
}
viewAnimator.setInAnimation(slideInLeft);
viewAnimator.setOutAnimation(slideOutRight);
viewAnimator.showPrevious();
onAnimationStarted(displayedChild, --displayedChild);
}
不知道我做错了什么。每个屏幕都有一个小文本,一个小图标和一个背景。背景大约每个1MB,分辨率为749 * 1311。不确定图像的大小是否是问题。如果是这样,我怎样才能使图像仍具有质量? 该应用程序已经在Nexus 5,三星S4,S3和S2上进行了测试,每次都有相同的结果。
我也试过用水平滚动视图做这个,但它仍然太慢了。