嵌套视图翻转器

发布于 2025-01-07 08:10:42 字数 10327 浏览 1 评论 0 原文

我正在尝试使用以下设置来设置嵌套的 viewflippers

Top_ViewFlipper
 - Type 1
   Sub_ViewFlipper
     - SubType 1
     - SubType 2
     - SubType 3
 - Type 2
   Sub_ViewFlipper
     - SubType 1
     - SubType 2
     - SubType 3

源可以在这里找到: https://github.com/platinummonkey/TXLF-App/tree/master/android 以下链接包含与此问题相关的所有 XML 和源代码(而不是查看文本墙):

的跟踪当前错误:

--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
D/KeyguardViewMediator(  981): wakeWhenReadyLocked(26)
I/power   (  981): *** set_screen_state 1
V/$$$$$$  ( 8060): In Method:  ACTION_SCREEN_ON
V/$$$$$$  ( 8060): In service onStart:  REGISTERED RECEIVER
D/SurfaceFlinger(  981): Screen about to return, flinger = 0x95b38
V/$$$$$$  ( 8060): In Method:  ACTION_USER_PRESENT
I/ActivityManager(  981): Start proc com.android.settings for broadcast com.android.settings/.widget.SettingsAppWidgetProvider: pid=8945 uid=1000 gids={1015, 3002, 3001, 3003}
W/InputManagerService(  981): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40699050
D/szipinf ( 8945): Initializing inflate state
V/$$$$$$  ( 8060): In service onStart:  REGISTERED RECEIVER
D/szipinf ( 8945): Initializing inflate state
D/SettingsAppWidgetProvider( 8945): Widget is from a previous version... Let's update
D/SettingsAppWidgetProvider( 8945): No instances yet... Wait for at least one instance to exist before adding global settings
I/ActivityManager(  981): No longer want com.anod.calendar (pid 8541): hidden #16
W/ActivityManager(  981): Scheduling restart of crashed service com.anod.calendar/.services.UpdateService in 5000ms
I/ActivityManager(  981): Start proc com.anod.calendar for service com.anod.calendar/.services.UpdateService: pid=8953 uid=10083 gids={1015}
D/dalvikvm(  967): GC_EXPLICIT freed 12K, 51% free 2674K/5379K, external 0K/0K, paused 133ms
D/szipinf ( 8953): Initializing inflate state
I/ActivityThread( 8953): Pub com.anod.calendar.events.provider: com.anod.calendar.scrollable.ScrollableDataProvider
I/dalvikvm( 8953): Could not find method android.appwidget.AppWidgetManager.notifyAppWidgetViewDataChanged, referenced from method com.anod.calendar.services.UpdateService.updateWidgets
D/dalvikvm(  967): GC_EXPLICIT freed <1K, 51% free 2674K/5379K, external 0K/0K, paused 63ms
W/dalvikvm( 8953): VFY: unable to resolve virtual method 151: Landroid/appwidget/AppWidgetManager;.notifyAppWidgetViewDataChanged ([II)V
D/dalvikvm( 8953): VFY: replacing opcode 0x6e at 0x0024
D/SimpleCal( 8953): Register content observer : 0
D/SimpleCal( 8953): Unregister content observer : 1
D/SimpleCal( 8953): Unregister content observer : 2
D/dalvikvm(  967): GC_EXPLICIT freed <1K, 51% free 2674K/5379K, external 0K/0K, paused 45ms
D/SimpleCal( 8953): Register content observer : 0
D/SimpleCal( 8953): Unregister content observer : 1
D/SimpleCal( 8953): Unregister content observer : 2
D/AndroidRuntime( 8964): 
D/AndroidRuntime( 8964): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
I/AndroidRuntime( 8964): Heap size: -Xmx32m
D/AndroidRuntime( 8964): CheckJNI is OFF
D/dalvikvm( 8964): creating instr width table
D/AndroidRuntime( 8964): Calling main entry com.android.commands.pm.Pm
D/AndroidRuntime( 8964): Shutting down VM
D/dalvikvm( 8964): GC_CONCURRENT freed 103K, 70% free 307K/1024K, external 0K/0K, paused 0ms+1ms
D/dalvikvm( 8964): Debugger has detached; object registry had 1 entries
I/AndroidRuntime( 8964): NOTE: attach of thread 'Binder Thread #3' failed
D/AndroidRuntime( 8974): 
D/AndroidRuntime( 8974): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
I/AndroidRuntime( 8974): Heap size: -Xmx32m
D/AndroidRuntime( 8974): CheckJNI is OFF
D/dalvikvm( 8974): creating instr width table
D/AndroidRuntime( 8974): Calling main entry com.android.commands.am.Am
I/ActivityManager(  981): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=org.texaslinuxfest.txlf/.TxlfActivity } from pid 8974
I/ActivityManager(  981): Start proc org.texaslinuxfest.txlf for activity org.texaslinuxfest.txlf/.TxlfActivity: pid=8982 uid=10100 gids={3003, 1006}
D/AndroidRuntime( 8974): Shutting down VM
D/dalvikvm( 8974): GC_CONCURRENT freed 103K, 69% free 325K/1024K, external 0K/0K, paused 0ms+1ms
D/dalvikvm( 8974): Debugger has detached; object registry had 1 entries
I/AndroidRuntime( 8974): NOTE: attach of thread 'Binder Thread #3' failed
E/jdwp    ( 8982): Failed sending reply to debugger: Broken pipe
D/dalvikvm( 8982): Debugger has detached; object registry had 1 entries
D/szipinf ( 8982): Initializing inflate state
D/dalvikvm( 8982): GC_EXTERNAL_ALLOC freed 44K, 50% free 2692K/5379K, external 0K/0K, paused 56ms
V/txlf    ( 8982): App already installed on your phone
D/txlf    ( 8982): Guide hasn't expired
V/txlf    ( 8982): Guide is ready - Sessions available
I/ActivityManager(  981): Displayed org.texaslinuxfest.txlf/.TxlfActivity: +406ms (total +4m46s12ms)
V/$$$$$$  ( 8060): In service onStart:  REGISTERED RECEIVER
I/ActivityManager(  981): Starting: Intent { cmp=org.texaslinuxfest.txlf/.Sessions (has extras) } from pid 8982
D/Sessions Activity( 8982): Got guide through intent Serializable
W/ResourceType( 8982): getEntry failing because entryIndex 12 is beyond type entryCount 12
W/ResourceType( 8982): Failure getting entry for 0x7f03000c (t=2 e=12) in package 0 (error -2147483647)
D/AndroidRuntime( 8982): Shutting down VM
W/dalvikvm( 8982): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime( 8982): FATAL EXCEPTION: main
E/AndroidRuntime( 8982): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.texaslinuxfest.txlf/org.texaslinuxfest.txlf.Sessions}: android.content.res.Resources$NotFoundException: Resource ID #0x7f03000c
E/AndroidRuntime( 8982):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
E/AndroidRuntime( 8982):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
E/AndroidRuntime( 8982):    at android.app.ActivityThread.access$1500(ActivityThread.java:123)
E/AndroidRuntime( 8982):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
E/AndroidRuntime( 8982):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 8982):    at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 8982):    at android.app.ActivityThread.main(ActivityThread.java:3835)
E/AndroidRuntime( 8982):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 8982):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 8982):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
E/AndroidRuntime( 8982):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
E/AndroidRuntime( 8982):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 8982): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f03000c
E/AndroidRuntime( 8982):    at android.content.res.Resources.getValue(Resources.java:929)
E/AndroidRuntime( 8982):    at android.content.res.Resources.loadXmlResourceParser(Resources.java:1955)
E/AndroidRuntime( 8982):    at android.content.res.Resources.getLayout(Resources.java:768)
E/AndroidRuntime( 8982):    at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
E/AndroidRuntime( 8982):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
E/AndroidRuntime( 8982):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:212)
E/AndroidRuntime( 8982):    at android.app.Activity.setContentView(Activity.java:1657)
E/AndroidRuntime( 8982):    at org.texaslinuxfest.txlf.Sessions.onCreate(Sessions.java:70)
E/AndroidRuntime( 8982):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 8982):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
E/AndroidRuntime( 8982):    ... 11 more
W/ActivityManager(  981):   Force finishing activity org.texaslinuxfest.txlf/.Sessions
W/ActivityManager(  981):   Force finishing activity org.texaslinuxfest.txlf/.TxlfActivity
W/ActivityManager(  981): Activity pause timeout for HistoryRecord{40708c48 org.texaslinuxfest.txlf/.Sessions}
I/ActivityManager(  981): No longer want com.android.defcontainer (pid 8900): hidden #16
I/Process ( 8982): Sending signal. PID: 8982 SIG: 9
I/ActivityManager(  981): Process org.texaslinuxfest.txlf (pid 8982) has died.
I/WindowManager(  981): WIN DEATH: Window{407c4aa8 org.texaslinuxfest.txlf/org.texaslinuxfest.txlf.TxlfActivity paused=true}
D/dalvikvm(  981): GC_CONCURRENT freed 1979K, 51% free 7640K/15431K, external 3673K/3889K, paused 12ms+11ms

现在它只是出错了,在我有一个主要 Viewflipper 工作之前两次提交,但嵌套它似乎已经破坏了东西......即使在手动将列表视图添加到嵌套 viewflipper 之后(而不是使用通用的) 方法)。 我在将子类型分配给适当的子Viewflipper 时遇到问题。有人有 XML 或编程方式的示例吗?我还没有找到任何使用嵌套视图翻转器的示例。选项卡主机可能可以工作,但我更喜欢纯文本按钮,并且喜欢 viewflipper 附带的动画。

I am trying to get nested viewflippers set up with the following setup

Top_ViewFlipper
 - Type 1
   Sub_ViewFlipper
     - SubType 1
     - SubType 2
     - SubType 3
 - Type 2
   Sub_ViewFlipper
     - SubType 1
     - SubType 2
     - SubType 3

Source can be found here: https://github.com/platinummonkey/TXLF-App/tree/master/android
The following links contain all the XML and source relevant to this problem (instead of viewing a wall of text):

Trace of Current Error:

--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
D/KeyguardViewMediator(  981): wakeWhenReadyLocked(26)
I/power   (  981): *** set_screen_state 1
V/$$$  ( 8060): In Method:  ACTION_SCREEN_ON
V/$$$  ( 8060): In service onStart:  REGISTERED RECEIVER
D/SurfaceFlinger(  981): Screen about to return, flinger = 0x95b38
V/$$$  ( 8060): In Method:  ACTION_USER_PRESENT
I/ActivityManager(  981): Start proc com.android.settings for broadcast com.android.settings/.widget.SettingsAppWidgetProvider: pid=8945 uid=1000 gids={1015, 3002, 3001, 3003}
W/InputManagerService(  981): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40699050
D/szipinf ( 8945): Initializing inflate state
V/$$$  ( 8060): In service onStart:  REGISTERED RECEIVER
D/szipinf ( 8945): Initializing inflate state
D/SettingsAppWidgetProvider( 8945): Widget is from a previous version... Let's update
D/SettingsAppWidgetProvider( 8945): No instances yet... Wait for at least one instance to exist before adding global settings
I/ActivityManager(  981): No longer want com.anod.calendar (pid 8541): hidden #16
W/ActivityManager(  981): Scheduling restart of crashed service com.anod.calendar/.services.UpdateService in 5000ms
I/ActivityManager(  981): Start proc com.anod.calendar for service com.anod.calendar/.services.UpdateService: pid=8953 uid=10083 gids={1015}
D/dalvikvm(  967): GC_EXPLICIT freed 12K, 51% free 2674K/5379K, external 0K/0K, paused 133ms
D/szipinf ( 8953): Initializing inflate state
I/ActivityThread( 8953): Pub com.anod.calendar.events.provider: com.anod.calendar.scrollable.ScrollableDataProvider
I/dalvikvm( 8953): Could not find method android.appwidget.AppWidgetManager.notifyAppWidgetViewDataChanged, referenced from method com.anod.calendar.services.UpdateService.updateWidgets
D/dalvikvm(  967): GC_EXPLICIT freed <1K, 51% free 2674K/5379K, external 0K/0K, paused 63ms
W/dalvikvm( 8953): VFY: unable to resolve virtual method 151: Landroid/appwidget/AppWidgetManager;.notifyAppWidgetViewDataChanged ([II)V
D/dalvikvm( 8953): VFY: replacing opcode 0x6e at 0x0024
D/SimpleCal( 8953): Register content observer : 0
D/SimpleCal( 8953): Unregister content observer : 1
D/SimpleCal( 8953): Unregister content observer : 2
D/dalvikvm(  967): GC_EXPLICIT freed <1K, 51% free 2674K/5379K, external 0K/0K, paused 45ms
D/SimpleCal( 8953): Register content observer : 0
D/SimpleCal( 8953): Unregister content observer : 1
D/SimpleCal( 8953): Unregister content observer : 2
D/AndroidRuntime( 8964): 
D/AndroidRuntime( 8964): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
I/AndroidRuntime( 8964): Heap size: -Xmx32m
D/AndroidRuntime( 8964): CheckJNI is OFF
D/dalvikvm( 8964): creating instr width table
D/AndroidRuntime( 8964): Calling main entry com.android.commands.pm.Pm
D/AndroidRuntime( 8964): Shutting down VM
D/dalvikvm( 8964): GC_CONCURRENT freed 103K, 70% free 307K/1024K, external 0K/0K, paused 0ms+1ms
D/dalvikvm( 8964): Debugger has detached; object registry had 1 entries
I/AndroidRuntime( 8964): NOTE: attach of thread 'Binder Thread #3' failed
D/AndroidRuntime( 8974): 
D/AndroidRuntime( 8974): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
I/AndroidRuntime( 8974): Heap size: -Xmx32m
D/AndroidRuntime( 8974): CheckJNI is OFF
D/dalvikvm( 8974): creating instr width table
D/AndroidRuntime( 8974): Calling main entry com.android.commands.am.Am
I/ActivityManager(  981): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=org.texaslinuxfest.txlf/.TxlfActivity } from pid 8974
I/ActivityManager(  981): Start proc org.texaslinuxfest.txlf for activity org.texaslinuxfest.txlf/.TxlfActivity: pid=8982 uid=10100 gids={3003, 1006}
D/AndroidRuntime( 8974): Shutting down VM
D/dalvikvm( 8974): GC_CONCURRENT freed 103K, 69% free 325K/1024K, external 0K/0K, paused 0ms+1ms
D/dalvikvm( 8974): Debugger has detached; object registry had 1 entries
I/AndroidRuntime( 8974): NOTE: attach of thread 'Binder Thread #3' failed
E/jdwp    ( 8982): Failed sending reply to debugger: Broken pipe
D/dalvikvm( 8982): Debugger has detached; object registry had 1 entries
D/szipinf ( 8982): Initializing inflate state
D/dalvikvm( 8982): GC_EXTERNAL_ALLOC freed 44K, 50% free 2692K/5379K, external 0K/0K, paused 56ms
V/txlf    ( 8982): App already installed on your phone
D/txlf    ( 8982): Guide hasn't expired
V/txlf    ( 8982): Guide is ready - Sessions available
I/ActivityManager(  981): Displayed org.texaslinuxfest.txlf/.TxlfActivity: +406ms (total +4m46s12ms)
V/$$$  ( 8060): In service onStart:  REGISTERED RECEIVER
I/ActivityManager(  981): Starting: Intent { cmp=org.texaslinuxfest.txlf/.Sessions (has extras) } from pid 8982
D/Sessions Activity( 8982): Got guide through intent Serializable
W/ResourceType( 8982): getEntry failing because entryIndex 12 is beyond type entryCount 12
W/ResourceType( 8982): Failure getting entry for 0x7f03000c (t=2 e=12) in package 0 (error -2147483647)
D/AndroidRuntime( 8982): Shutting down VM
W/dalvikvm( 8982): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime( 8982): FATAL EXCEPTION: main
E/AndroidRuntime( 8982): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.texaslinuxfest.txlf/org.texaslinuxfest.txlf.Sessions}: android.content.res.Resources$NotFoundException: Resource ID #0x7f03000c
E/AndroidRuntime( 8982):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
E/AndroidRuntime( 8982):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
E/AndroidRuntime( 8982):    at android.app.ActivityThread.access$1500(ActivityThread.java:123)
E/AndroidRuntime( 8982):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
E/AndroidRuntime( 8982):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 8982):    at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 8982):    at android.app.ActivityThread.main(ActivityThread.java:3835)
E/AndroidRuntime( 8982):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 8982):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 8982):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
E/AndroidRuntime( 8982):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
E/AndroidRuntime( 8982):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 8982): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f03000c
E/AndroidRuntime( 8982):    at android.content.res.Resources.getValue(Resources.java:929)
E/AndroidRuntime( 8982):    at android.content.res.Resources.loadXmlResourceParser(Resources.java:1955)
E/AndroidRuntime( 8982):    at android.content.res.Resources.getLayout(Resources.java:768)
E/AndroidRuntime( 8982):    at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
E/AndroidRuntime( 8982):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
E/AndroidRuntime( 8982):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:212)
E/AndroidRuntime( 8982):    at android.app.Activity.setContentView(Activity.java:1657)
E/AndroidRuntime( 8982):    at org.texaslinuxfest.txlf.Sessions.onCreate(Sessions.java:70)
E/AndroidRuntime( 8982):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 8982):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
E/AndroidRuntime( 8982):    ... 11 more
W/ActivityManager(  981):   Force finishing activity org.texaslinuxfest.txlf/.Sessions
W/ActivityManager(  981):   Force finishing activity org.texaslinuxfest.txlf/.TxlfActivity
W/ActivityManager(  981): Activity pause timeout for HistoryRecord{40708c48 org.texaslinuxfest.txlf/.Sessions}
I/ActivityManager(  981): No longer want com.android.defcontainer (pid 8900): hidden #16
I/Process ( 8982): Sending signal. PID: 8982 SIG: 9
I/ActivityManager(  981): Process org.texaslinuxfest.txlf (pid 8982) has died.
I/WindowManager(  981): WIN DEATH: Window{407c4aa8 org.texaslinuxfest.txlf/org.texaslinuxfest.txlf.TxlfActivity paused=true}
D/dalvikvm(  981): GC_CONCURRENT freed 1979K, 51% free 7640K/15431K, external 3673K/3889K, paused 12ms+11ms

Right Now it just errors out, two commits prior I had one primary Viewflipper working, but nesting it seems to have broken things... even after manually adding listviews to the nested viewflipper (instead of using a generic method).
I am having trouble assigning assigning the SubTypes to the appropriate subViewflipper. Does anyone have an example of this either XML or programmatically? I have yet to find any examples on using nested viewflippers. Optionally tab host might work, but I would prefer text-only buttons and do like the animations that come with viewflipper.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄情伤 2025-01-14 08:10:42

GITHUB 仓库: https://github.com/agoransson/nested_view_flippers

好吧,这将是一个很大的答案。 ..但我希望这就是您正在寻找的。

活动:

    private GestureDetector gestureScanner;
private ViewFlipper rootFlipper;
private ViewFlipper flipper1, flipper2;

private Animation animFlipInNext, animFlipOutNext;
private Animation animFlipInPrevious, animFlipOutPrevious;
private Animation rootAnimFlipInNext, rootAnimFlipOutNext;
private Animation rootAnimFlipInPrevious, rootAnimFlipOutPrevious;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Root flipper
    rootFlipper = (ViewFlipper) findViewById(R.id.rootFlipper);

    // Content flippers
    flipper1 = (ViewFlipper) findViewById(R.id.viewFlipper1);
    flipper2 = (ViewFlipper) findViewById(R.id.viewFlipper2);

    gestureScanner = new GestureDetector(this);

    // Animations
    animFlipInNext = AnimationUtils.loadAnimation(this, R.anim.flipinnext);
    animFlipOutNext = AnimationUtils.loadAnimation(this, R.anim.flipoutnext);
    animFlipInPrevious = AnimationUtils.loadAnimation(this,
            R.anim.flipinprevious);
    animFlipOutPrevious = AnimationUtils.loadAnimation(this,
            R.anim.flipoutprevious);

    rootAnimFlipInNext = AnimationUtils.loadAnimation(this,
            R.anim.rootflipinnext);
    rootAnimFlipOutNext = AnimationUtils.loadAnimation(this,
            R.anim.rootflipoutnext);
    rootAnimFlipInPrevious = AnimationUtils.loadAnimation(this,
            R.anim.rootflipinprevious);
    rootAnimFlipOutPrevious = AnimationUtils.loadAnimation(this,
            R.anim.rootflipoutprevious);
}
    @Override
public boolean onTouchEvent(MotionEvent event) {
    return gestureScanner.onTouchEvent(event);
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
        float velocityY) {

    Log.i("TEST", "Fling!!");

    if (Math.abs(velocityY) > Math.abs(velocityX)) {
        if (velocityY > 0) {
            rootFlipper.setInAnimation(rootAnimFlipInNext);
            rootFlipper.setOutAnimation(rootAnimFlipOutNext);
            rootFlipper.showNext();
        } else if (velocityY < 0) {
            rootFlipper.setInAnimation(rootAnimFlipInPrevious);
            rootFlipper.setOutAnimation(rootAnimFlipOutPrevious);
            rootFlipper.showPrevious();
        }
    } else {
        if (velocityX > 0) {
            ViewFlipper v = (ViewFlipper) rootFlipper.getCurrentView();
            v.setInAnimation(animFlipInNext);
            v.setOutAnimation(animFlipOutNext);
            v.showNext();
        } else if (velocityX < 0) {
            ViewFlipper v = (ViewFlipper) rootFlipper.getCurrentView();
            v.setInAnimation(animFlipInPrevious);
            v.setOutAnimation(animFlipOutPrevious);
            v.showPrevious();
        }
    }
    return true;
}

布局:

<?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="vertical" >

<ViewFlipper
    android:id="@+id/rootFlipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ViewFlipper
        android:id="@+id/viewFlipper1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:id="@+id/innerone"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ff0000"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LAYOUT 1-1"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/innertwo"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ff0000"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LAYOUT 1-2"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/innerthree"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ff0000"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LAYOUT 1-3"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>
    </ViewFlipper>

    <ViewFlipper
        android:id="@+id/viewFlipper2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:id="@+id/innerone"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#00ff00"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LAYOUT 2-1"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/innertwo"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#00ff00"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LAYOUT 2-2"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/innerthree"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#00ff00"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LAYOUT 2-3"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>
    </ViewFlipper>
</ViewFlipper>

</LinearLayout>

动画:

Flipinnext.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator" >
<translate
    android:duration="500"
    android:fromXDelta="-100%"
    android:toXDelta="0%" />
</set>

Flipinprevious.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator" >
<translate
    android:duration="500"
    android:fromXDelta="100%"
    android:toXDelta="0%" />
</set>

Flipoutnext.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator" >

<translate
    android:duration="500"
    android:fromXDelta="0%"
    android:toXDelta="100%" />

</set>

FlipoutPrevious.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator" >

<translate
    android:duration="500"
    android:fromXDelta="0%"
    android:toXDelta="-100%" />

</set>

然后您需要一组几乎相同的动画用于根翻转(y 轴)。只需复制 x 轴动画并将平移属性更改为 Y 轴即可。

GITHUB repo: https://github.com/agoransson/nested_view_flippers

Okay, this will be a big answer... but I hope it's what you were looking for.

The activity:

    private GestureDetector gestureScanner;
private ViewFlipper rootFlipper;
private ViewFlipper flipper1, flipper2;

private Animation animFlipInNext, animFlipOutNext;
private Animation animFlipInPrevious, animFlipOutPrevious;
private Animation rootAnimFlipInNext, rootAnimFlipOutNext;
private Animation rootAnimFlipInPrevious, rootAnimFlipOutPrevious;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Root flipper
    rootFlipper = (ViewFlipper) findViewById(R.id.rootFlipper);

    // Content flippers
    flipper1 = (ViewFlipper) findViewById(R.id.viewFlipper1);
    flipper2 = (ViewFlipper) findViewById(R.id.viewFlipper2);

    gestureScanner = new GestureDetector(this);

    // Animations
    animFlipInNext = AnimationUtils.loadAnimation(this, R.anim.flipinnext);
    animFlipOutNext = AnimationUtils.loadAnimation(this, R.anim.flipoutnext);
    animFlipInPrevious = AnimationUtils.loadAnimation(this,
            R.anim.flipinprevious);
    animFlipOutPrevious = AnimationUtils.loadAnimation(this,
            R.anim.flipoutprevious);

    rootAnimFlipInNext = AnimationUtils.loadAnimation(this,
            R.anim.rootflipinnext);
    rootAnimFlipOutNext = AnimationUtils.loadAnimation(this,
            R.anim.rootflipoutnext);
    rootAnimFlipInPrevious = AnimationUtils.loadAnimation(this,
            R.anim.rootflipinprevious);
    rootAnimFlipOutPrevious = AnimationUtils.loadAnimation(this,
            R.anim.rootflipoutprevious);
}
    @Override
public boolean onTouchEvent(MotionEvent event) {
    return gestureScanner.onTouchEvent(event);
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
        float velocityY) {

    Log.i("TEST", "Fling!!");

    if (Math.abs(velocityY) > Math.abs(velocityX)) {
        if (velocityY > 0) {
            rootFlipper.setInAnimation(rootAnimFlipInNext);
            rootFlipper.setOutAnimation(rootAnimFlipOutNext);
            rootFlipper.showNext();
        } else if (velocityY < 0) {
            rootFlipper.setInAnimation(rootAnimFlipInPrevious);
            rootFlipper.setOutAnimation(rootAnimFlipOutPrevious);
            rootFlipper.showPrevious();
        }
    } else {
        if (velocityX > 0) {
            ViewFlipper v = (ViewFlipper) rootFlipper.getCurrentView();
            v.setInAnimation(animFlipInNext);
            v.setOutAnimation(animFlipOutNext);
            v.showNext();
        } else if (velocityX < 0) {
            ViewFlipper v = (ViewFlipper) rootFlipper.getCurrentView();
            v.setInAnimation(animFlipInPrevious);
            v.setOutAnimation(animFlipOutPrevious);
            v.showPrevious();
        }
    }
    return true;
}

The layout:

<?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="vertical" >

<ViewFlipper
    android:id="@+id/rootFlipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ViewFlipper
        android:id="@+id/viewFlipper1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:id="@+id/innerone"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ff0000"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LAYOUT 1-1"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/innertwo"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ff0000"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LAYOUT 1-2"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/innerthree"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ff0000"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LAYOUT 1-3"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>
    </ViewFlipper>

    <ViewFlipper
        android:id="@+id/viewFlipper2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:id="@+id/innerone"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#00ff00"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LAYOUT 2-1"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/innertwo"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#00ff00"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LAYOUT 2-2"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/innerthree"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#00ff00"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LAYOUT 2-3"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>
    </ViewFlipper>
</ViewFlipper>

</LinearLayout>

The animations:

flipinnext.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator" >
<translate
    android:duration="500"
    android:fromXDelta="-100%"
    android:toXDelta="0%" />
</set>

flipinprevious.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator" >
<translate
    android:duration="500"
    android:fromXDelta="100%"
    android:toXDelta="0%" />
</set>

flipoutnext.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator" >

<translate
    android:duration="500"
    android:fromXDelta="0%"
    android:toXDelta="100%" />

</set>

flipoutprevious.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator" >

<translate
    android:duration="500"
    android:fromXDelta="0%"
    android:toXDelta="-100%" />

</set>

And then you need a set of almost identical animations for the root flip (y-axis). Just copy the x-axis animations and change the translate attributes to the Y-axis.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文