简体   繁体   English

我如何使用像ViewPagger这样的Android VIewAnimation翻转屏幕

[英]How i can do Flipping screen with Android VIewAnimation like ViewPagger

I am using ViewAnimation : 我正在使用ViewAnimation:

With the help of view Animation , How i can swap the Screen from left to right and right to left like viewPagger . 在视图动画的帮助下,我如何可以像viewPagger一样从左到右和从右到左交换屏幕。 As I know ,we can do it with Touch , but it is not right way , In Touch Mode , when i click on Screen , next screen will be visible , But I need Like 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>

How i can get this approach with the help of ViewAnimation or Gesture with left scrolling or Right scrolling.| 如何通过左滚动或右滚动在ViewAnimation或Gesture的帮助下获得此方法 There is any way to flip the screen as animation left in and animation right in using translation,scale , rotation etc 有任何方法可以在动画离开时翻转屏幕,并使用平移,缩放,旋转等动画 在此输入图像描述

如果你愿意在你的项目中使用库..它可以帮助你https://github.com/JakeWharton/Android-ViewPagerIndicator

The following links may help you to achieve your requirement. 以下链接可帮助您实现您的要求。 It is same like your screenshots that you attached(Google Play like home screen). 它与您附加的屏幕截图相同(Google Play就像主屏幕一样)。

1) https://github.com/astuetz/ViewPagerExtensions 1) https://github.com/astuetz/ViewPagerExtensions

2) https://github.com/astuetz/android-viewpagertabs 2) https://github.com/astuetz/android-viewpagertabs

for left_in.xml 对于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>

for left_out.xml 对于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>

you need to create both of animation xml file under /res/animator folder. 你需要在/ res / animator文件夹下创建两个动画xml文件。 Using follow code to apply the animation to View or Activity 使用以下代码将动画应用于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.

相关问题 我如何在 Android 中制作动态翻转屏幕(如 iPhone 的) - How can i make a dynamic flipping screen(like that of iPhone) in Android 我该如何渲染屏幕 - How can i Render screen like this 如何使View.OnScrollChangeListener在适用于Android 23(棉花糖)及更低版本的ViewPagger上工作 - How to make View.OnScrollChangeListener works on ViewPagger for android version 23 (Marshmallow) and below 如何在 Android 中执行类似 FlowLayout 的操作? - How can I do something like a FlowLayout in Android? 我如何在每周几天的小时内,在诸如Analytics(分析)Android应用之类的网络中获取屏幕? - how can i get the screen per hours on days of the weeks, in web like analytics android app? 如何创建可以像Facebook通知一样在屏幕上移动的浮动广告? - How do I create a floater that I can move all over the screen like the Facebook notification? 如何在Android设置屏幕中获取包装的ListView? - How do I get a wrapped ListView like the one in the Android Setup Screen? 如何在Android中显示启动画面? - How do I show a splash screen in Android? 如何在Android上检测屏幕旋转? - How do I detect screen rotation on android? 在Android中使用ViewAnimation或PropertyAnimation旋转图像 - Rotation of image using ViewAnimation or PropertyAnimation in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM