![](/img/trans.png)
[英]How i can do Flipping screen with Android VIewAnimation like ViewPagger
[英]How can i make a dynamic flipping screen(like that of iPhone) in Android
我正在通過網絡服務解析數據。 我想要水平翻轉而不是垂直翻轉。 這是一個使用 ViewFlipper 的教程,但它用於靜態數據。
這是我們需要在 2 個活動之間切換的代碼:
飛濺.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();
}
}
飛濺.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>
菜單.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);
}
}
菜單文件
<?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>
您可以使用 addView 動態地將頁面添加到 ViewFlipper。
flipper= (ViewFlipper) findViewById(R.id.flipper1);
flipper.addView(myView,myViewIndex);
其中 myView 是您要添加的視圖,而 myViewIndex 是您要添加此新視圖的 viewflipper 中的索引。
然后,您可以將動畫設置為在更改視圖時執行:
flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.left_in));
flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.left_out));
然后翻到這個頁面,你可以使用:
flipper.setDisplayedChild(myViewIndex);
其中 left_in.xml 定義為
<?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>
和 left_out.xml 是:
<?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>
剛剛快速找了找你,因為我確定我以前見過它,我在 developer.android.com 上找到了這個:
public void overridePendingTransition (int enterAnim, int exitAnim)
Since: API Level 5
Call immediately after one of the flavors of startActivity(Intent) or finish() to specify an explicit transition animation to perform next.
Parameters
enterAnim A resource ID of the animation resource to use for the incoming activity. Use 0 for no animation.
exitAnim A resource ID of the animation resource to use for the outgoing activity. Use 0 for no animation.
因此,您可以將此額外參數添加到您的意圖中,這將定義您調用的活動在新活動進入和舊活動退出時將如何動畫化。
如果您想在兩個活動之間導航而不使用視圖翻轉器,您可以使用普通意圖。 寫了一個教程,這樣你就可以動畫你的活動進出,
享受:
您是否只希望屏幕根據其保持的位置(由加速度計傳感器確定)旋轉?
如果是這樣,只需添加
android:screenOrientation="sensor"
到您的 AndroidManifest.xml 文件中的 Activity 節點
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.