[英]How can i make a dynamic flipping screen(like that of iPhone) in Android
[英]How i can do Flipping screen with Android VIewAnimation like ViewPagger
我正在使用ViewAnimation:
在視圖動畫的幫助下,我如何可以像viewPagger一樣從左到右和從右到左交換屏幕。 據我所知,我們可以通過Touch實現,但這不是正確的方式,在觸摸模式下,當我點擊屏幕時,下一個屏幕將可見,但我需要像ViewPagger。
<!-- This is View Animation Xml code, In which we have two Layout(Screen) one for GridView and WebView and Second Layout Screen for ListView and WebView -->
<ViewAnimator
android:id="@+id/viewSwitcher_ID" <ViewAnimator
android:id="@+id/viewSwitcher_ID"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="@+id/linear_wWeb"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:columnWidth="500dp"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="10dip"
android:layout_marginBottom="5dip"
android:background="@drawable/list_selector"
android:stretchMode="columnWidth"
android:gravity="center" />
<WebView
android:id="@+id/webGrid_ID"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/webview_div"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:id="@+id/linear_wList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="5" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical" >
<ListView
android:id="@+id/mylist"
android:layout_width="wrap_content"
android:layout_height="530dp"
android:background="@drawable/list_selector" >
</ListView>
<RelativeLayout
android:id="@+id/gallery_relative_layout"
android:layout_width="fill_parent"
android:layout_height="70dip"
android:layout_gravity="bottom"
android:background="@drawable/headertest"
android:paddingLeft="4dip"
android:paddingRight="4dip"
android:paddingTop="5dip"
android:paddingBottom="5dip"
android:layout_marginBottom="20dip"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/leftArrow"
android:layout_width="40dip"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dip"
android:background="@drawable/fleft_arrow" />
<HorizontalScrollView
android:id="@+id/horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/rightArrow"
android:layout_toRightOf="@+id/leftArrow" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center_horizontal|bottom"
android:orientation="horizontal"
android:layout_marginBottom="5dip"
android:layout_alignParentBottom="true" >
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector1" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector2" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector3" />
<Button
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector4" />
<Button
android:id="@+id/button5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector5" />
<Button
android:id="@+id/button6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector6" />
<Button
android:id="@+id/button7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector7" />
<Button
android:id="@+id/button8"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector8" />
</LinearLayout>
</HorizontalScrollView>
<ImageButton
android:id="@+id/rightArrow"
android:layout_width="40dip"
android:layout_height="50dip"
android:layout_marginBottom="5dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@drawable/fright_arrow"
/>
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="fill_parent"
android:background="@android:color/black" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="3"
android:background="@drawable/webview_div">
<WebView
android:id="@+id/webviewFirstLinear"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="3" />
</LinearLayout>
</LinearLayout>
</ViewAnimator>
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="@+id/linear_wWeb"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:columnWidth="500dp"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="10dip"
android:layout_marginBottom="5dip"
android:background="@drawable/list_selector"
android:stretchMode="columnWidth"
android:gravity="center" />
<WebView
android:id="@+id/webGrid_ID"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/webview_div"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:visibility="gone"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/linear_wList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="5" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical" >
<ListView
android:id="@+id/mylist"
android:layout_width="wrap_content"
android:layout_height="530dp"
android:background="@drawable/list_selector" >
</ListView>
<RelativeLayout
android:id="@+id/gallery_relative_layout"
android:layout_width="fill_parent"
android:layout_height="70dip"
android:layout_gravity="bottom"
android:background="@drawable/headertest"
android:paddingLeft="4dip"
android:paddingRight="4dip"
android:paddingTop="5dip"
android:paddingBottom="5dip"
android:layout_marginBottom="20dip"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/leftArrow"
android:layout_width="40dip"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dip"
android:background="@drawable/fleft_arrow" />
<HorizontalScrollView
android:id="@+id/horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/rightArrow"
android:layout_toRightOf="@+id/leftArrow" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center_horizontal|bottom"
android:orientation="horizontal"
android:layout_marginBottom="5dip"
android:layout_alignParentBottom="true" >
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector1" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector2" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector3" />
<Button
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector4" />
<Button
android:id="@+id/button5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector5" />
<Button
android:id="@+id/button6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector6" />
<Button
android:id="@+id/button7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector7" />
<Button
android:id="@+id/button8"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector8" />
</LinearLayout>
</HorizontalScrollView>
<ImageButton
android:id="@+id/rightArrow"
android:layout_width="40dip"
android:layout_height="50dip"
android:layout_marginBottom="5dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@drawable/fright_arrow"
/>
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="fill_parent"
android:background="@android:color/black" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="3"
android:background="@drawable/webview_div">
<WebView
android:id="@+id/webviewFirstLinear"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="3" />
</LinearLayout>
</LinearLayout>
</ViewAnimator>
如何通過左滾動或右滾動在ViewAnimation或Gesture的幫助下獲得此方法 有任何方法可以在動畫離開時翻轉屏幕,並使用平移,縮放,旋轉等動畫
如果你願意在你的項目中使用庫..它可以幫助你https://github.com/JakeWharton/Android-ViewPagerIndicator
以下鏈接可幫助您實現您的要求。 它與您附加的屏幕截圖相同(Google Play就像主屏幕一樣)。
對於left_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Before rotating, immediately set the alpha to 0. -->
<objectAnimator
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:duration="0" />
<!-- Rotate. -->
<objectAnimator
android:valueFrom="-180"
android:valueTo="0"
android:propertyName="rotationY"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:duration="@integer/card_flip_time_full" />
<!-- Half-way through the rotation (see startOffset), set the alpha to 1. -->
<objectAnimator
android:valueFrom="0.0"
android:valueTo="1.0"
android:propertyName="alpha"
android:startOffset="@integer/card_flip_time_half"
android:duration="1" />
</set>
對於left_out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Rotate. -->
<objectAnimator
android:valueFrom="0"
android:valueTo="-180"
android:propertyName="rotationY"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:duration="@integer/card_flip_time_full" />
<!-- Half-way through the rotation (see startOffset), set the alpha to 0. -->
<objectAnimator
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:startOffset="@integer/card_flip_time_half"
android:duration="1" />
</set>
你需要在/ res / animator文件夾下創建兩個動畫xml文件。 使用以下代碼將動畫應用於View或Activity
Intent i = new Intent(first.this, second.class);
startActivity(i);
overridePendingTransition(R.animator.push_left_in,R.animator.push_left_out);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.