如何滑动到下一个活动
我在我的应用程序中使用viewflipper 和gestureDetector 来滑动页面。我能够交换页面。现在我想继续我的应用程序中关于 swapleft 方法的下一个活动。 在 swapleft 中,我添加了一个方法 page.showNext()。现在我想切换到下一个活动。
这是我的 Activity.class
public class eDetailing extends Activity
{
ViewFlipper page;
Animation animFlipInForeward;
Animation animFlipOutForeward;
Animation animFlipInBackward;
Animation animFlipOutBackward;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
page = (ViewFlipper)findViewById(R.id.main_flipper_view);
animFlipInForeward = AnimationUtils.loadAnimation(this, R.anim.flipin);
animFlipOutForeward = AnimationUtils.loadAnimation(this, R.anim.flipout);
animFlipInBackward = AnimationUtils.loadAnimation(this, R.anim.flipin_reverse);
animFlipOutBackward = AnimationUtils.loadAnimation(this, R.anim.flipout_reverse);
//findViewById(R.id.main_linear).setOnClickListener(this);
}
private void SwipeRight(){
page.setInAnimation(animFlipInBackward);
page.setOutAnimation(animFlipOutBackward);
page.showPrevious();
}
private void SwipeLeft(){
page.setInAnimation(animFlipInForeward);
page.setOutAnimation(animFlipOutForeward);
page.showNext();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
SimpleOnGestureListener simpleOnGestureListener
= new SimpleOnGestureListener(){
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
float sensitvity = 50;
if((e1.getX() - e2.getX()) > sensitvity){
SwipeLeft();
}else if((e2.getX() - e1.getX()) > sensitvity){
SwipeRight();
}
return true;
}
};
GestureDetector gestureDetector
= new GestureDetector(simpleOnGestureListener);
}
这是我的 xml 文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal">
<ViewFlipper
android:id="@+id/main_flipper_view"
android:layout_height="540dip" android:layout_width="1020dip">
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="horizontal">
<ImageView android:id="@+id/main_imageview" android:background="@drawable/img_main" android:layout_height="fill_parent" android:layout_width="fill_parent"></ImageView>
</LinearLayout>
</ViewFlipper>
,我在动画中使用 Flipin、flipout、flipinreverse、flipoutreverse xml 文件。 谁能有想法吗?
另外我想在活动上添加菜单,菜单将操作不同的页面。 使用viewflipper和gestureDetector的页面滑动效果可以实现吗?
提前致谢。
i am using viewflipper and gesturedetector in my application for swiping the pages.i am able to swap a page. now i want to go on the next activity in my application on swapleft method.
in the swapleft i added one method page.showNext().now i want to switch to next activity.
here it is my activity.class
public class eDetailing extends Activity
{
ViewFlipper page;
Animation animFlipInForeward;
Animation animFlipOutForeward;
Animation animFlipInBackward;
Animation animFlipOutBackward;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
page = (ViewFlipper)findViewById(R.id.main_flipper_view);
animFlipInForeward = AnimationUtils.loadAnimation(this, R.anim.flipin);
animFlipOutForeward = AnimationUtils.loadAnimation(this, R.anim.flipout);
animFlipInBackward = AnimationUtils.loadAnimation(this, R.anim.flipin_reverse);
animFlipOutBackward = AnimationUtils.loadAnimation(this, R.anim.flipout_reverse);
//findViewById(R.id.main_linear).setOnClickListener(this);
}
private void SwipeRight(){
page.setInAnimation(animFlipInBackward);
page.setOutAnimation(animFlipOutBackward);
page.showPrevious();
}
private void SwipeLeft(){
page.setInAnimation(animFlipInForeward);
page.setOutAnimation(animFlipOutForeward);
page.showNext();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
SimpleOnGestureListener simpleOnGestureListener
= new SimpleOnGestureListener(){
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
float sensitvity = 50;
if((e1.getX() - e2.getX()) > sensitvity){
SwipeLeft();
}else if((e2.getX() - e1.getX()) > sensitvity){
SwipeRight();
}
return true;
}
};
GestureDetector gestureDetector
= new GestureDetector(simpleOnGestureListener);
}
here it is my xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal">
<ViewFlipper
android:id="@+id/main_flipper_view"
android:layout_height="540dip" android:layout_width="1020dip">
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="horizontal">
<ImageView android:id="@+id/main_imageview" android:background="@drawable/img_main" android:layout_height="fill_parent" android:layout_width="fill_parent"></ImageView>
</LinearLayout>
</ViewFlipper>
and i am using flipin,flipout,flipinreverse,flipoutreverse xml files in anim.
could anyone have an idea?
Also i want to add menu on the activity and menu will operate different pages.
is this possible with page swiping effect using viewflipper and gesturedetector?
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调用 startActivity
Call startActivity
你可以这样做
}
U Can do like this
}