Android -视图切换器



我想动态添加一个视图切换器。

  ViewSwitcher switcher = new ViewSwitcher(this);

我如何添加我的两个布局到视图切换器和视图之间使用代码切换?

错误:

A1 [Android Application]    
DalvikVM[localhost:8604] (may be out of synch)  
    Thread [<1> main] (Suspended (exception RuntimeException))  
        ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1815    
        ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1831 
        ActivityThread.access$500(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 122    
        ActivityThread$H.handleMessage(Message) line: 1024  
        ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
        Looper.loop() line: 132 
        ActivityThread.main(String[]) line: 4123    
        Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
        Method.invoke(Object, Object...) line: 491  
        ZygoteInit$MethodAndArgsCaller.run() line: 841  
        ZygoteInit.main(String[]) line: 599 
        NativeStart.main(String[]) line: not available [native method]  
    Thread [<8> Binder Thread #2] (Running) (may be out of synch)   
    Thread [<7> Binder Thread #1] (Running) (may be out of synch)   
    Thread [<9> SoundPool] (Running) (may be out of synch)  
    Thread [<10> SoundPoolThread] (Running) (may be out of synch)   

http://developer.android.com/reference/android/widget/ViewSwitcher.html

公共方法
void     addView(View child, int index, ViewGroup.LayoutParams params)

添加具有指定布局参数的子视图。

参考ViewSwitcher的Android文档。您可以根据需要使用addView()showNext()方法。

两次调用索引为0和1的addView

addView(child, index, 
           new ViewGroup.LayoutParams(
                     LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

相关内容

最新更新