android程序通过ViewFlipper实现滑动屏幕切换图片,可是没有效果,Activity都无法打开是什么原因造成的? 10
代码如下packagecom.example.leslie_app;importandroid.app.Activity;importandroid.os.Bundle;...
代码如下
package com.example.leslie_app;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ViewFlipper;
public abstract class zhangguorongxzh_Activity extends Activity {
ViewFlipper ViewFlipper=null;
float startX;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.zhangguorongxzhen);
init();
}
private void init() {
// TODO Auto-generated method stub
ViewFlipper=(ViewFlipper)super.findViewById(R.id.ViewFlipper);
}
@Override
public boolean onTouchEvent(MotionEvent event){
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
startX=event.getX();
break;
case MotionEvent.ACTION_UP:
if(event.getX()>startX){
ViewFlipper.setInAnimation(this,R.anim.in_left2right);
ViewFlipper.setInAnimation(this,R.anim.out_left2right);
ViewFlipper.showNext();
}else if(event.getX()<startX){
ViewFlipper.setInAnimation(this,R.anim.in_right2left);
ViewFlipper.setInAnimation(this,R.anim.out_right2left);
ViewFlipper.showPrevious();
}
break;
}
return super.onTouchEvent(event);
}
} 展开
package com.example.leslie_app;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ViewFlipper;
public abstract class zhangguorongxzh_Activity extends Activity {
ViewFlipper ViewFlipper=null;
float startX;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.zhangguorongxzhen);
init();
}
private void init() {
// TODO Auto-generated method stub
ViewFlipper=(ViewFlipper)super.findViewById(R.id.ViewFlipper);
}
@Override
public boolean onTouchEvent(MotionEvent event){
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
startX=event.getX();
break;
case MotionEvent.ACTION_UP:
if(event.getX()>startX){
ViewFlipper.setInAnimation(this,R.anim.in_left2right);
ViewFlipper.setInAnimation(this,R.anim.out_left2right);
ViewFlipper.showNext();
}else if(event.getX()<startX){
ViewFlipper.setInAnimation(this,R.anim.in_right2left);
ViewFlipper.setInAnimation(this,R.anim.out_right2left);
ViewFlipper.showPrevious();
}
break;
}
return super.onTouchEvent(event);
}
} 展开
2个回答
展开全部
报错了吧,报的什么错拿出来看下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询