我怎样才能使Android的动态翻转屏(像iPhone的) [英] How can i make a dynamic flipping screen(like that of iPhone) in Android
问题描述
我通过Web Service分析数据。我想翻转横向而不是纵向。这里是ViewFlipper使用的教程,但它是静态数据。
下面是我们的code,我们需要2活动之间翻转:
Splash.java
公共类飞溅延伸活动{
/ **第一次创建活动时调用。 * /
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
startActivity(新意图(Splash.this,MainMenu.class));
Splash.this.finish();
}
}
Splash.xml
< XML版本=1.0编码=UTF-8&GT?;
< AbsoluteLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=@可绘制/扑通一声>
< / AbsoluteLayout>
Menu.java
公共类菜单扩展活动{
/ **第一次创建活动时调用。 * /
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.menu);
}
}
menu.xml文件
< XML版本=1.0编码=UTF-8&GT?;
< AbsoluteLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=@可绘制/菜单>
< / AbsoluteLayout>
您可以动态使用addView页面添加到ViewFlipper。
鳍状肢=(ViewFlipper)findViewById(R.id.flipper1);
flipper.addView(MyView的,myViewIndex);
在哪里MyView的是你要添加的视图,myViewIndex是该指数中要添加这个新观点的viewflipper。
您可以再设置动画preform不断变化的看法:
flipper.setInAnimation(AnimationUtils.loadAnimation(这一点,R.anim.left_in));
flipper.setOutAnimation(AnimationUtils.loadAnimation(这一点,R.anim.left_out));
然后翻转到这个页面,您可以使用:
flipper.setDisplayedChild(myViewIndex);
在哪里left_in.xml被定义为
< XML版本=1.0编码=UTF-8&GT?;
<设置的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:插=@机器人:动画/ accelerate_interpolator>
<翻译
机器人:插=@机器人:动画/ decelerate_interpolator
机器人:fromXDelta =100%P
机器人:toXDelta =0
机器人:时间=300
/>
< /集>
和left_out.xml是:
< XML版本=1.0编码=UTF-8&GT?;
<设置的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:插=@机器人:动画/ accelerate_interpolator
>
<翻译
机器人:插=@机器人:动画/ decelerate_interpolator
机器人:fromXDelta =0
机器人:toXDelta = - 100%P
机器人:时间=300
/>
< /集>
I am parsing data through the web service. I want the flipping horizontally rather than vertically. Here is a tutorial where ViewFlipper is used but it is for static data.
Here is our code where we need flipping between 2 activities:
Splash.java
public class Splash extends Activity{
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startActivity(new Intent(Splash.this, MainMenu.class));
Splash.this.finish();
}
}
Splash.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/splash">
</AbsoluteLayout>
Menu.java
public class Menu extends Activity{
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
}
}
Menu.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/menu">
</AbsoluteLayout>
You can add pages to a ViewFlipper dynamically using addView.
flipper= (ViewFlipper) findViewById(R.id.flipper1);
flipper.addView(myView,myViewIndex);
Where myView is the view you wish to add, and myViewIndex is the index in the viewflipper you want to add this new view.
You can then set the animations to preform on changing of views:
flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.left_in));
flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.left_out));
Then to flip to this page you can use:
flipper.setDisplayedChild(myViewIndex);
Where left_in.xml is defined as
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate
android:interpolator="@android:anim/decelerate_interpolator"
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="300"
/>
</set>
and left_out.xml is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
>
<translate
android:interpolator="@android:anim/decelerate_interpolator"
android:fromXDelta="0"
android:toXDelta="-100%p"
android:duration="300"
/>
</set>
这篇关于我怎样才能使Android的动态翻转屏(像iPhone的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!