我的视图鳍状肢无法正常工作

时间:2013-08-21 12:44:21

标签: android

您好我已经在我的活动中创建了一个视图翻录器并且它无法正常工作,当单击视图翻转器的选项卡时,应用程序突然停止,我已在清单文件中添加了活动但它无法正常工作,我需要一个更好的解决方案,我在下面给我的logcat

08-21 12:33:56.781: E/AndroidRuntime(28171): FATAL EXCEPTION: main

08-21 12:33:56.781: E/AndroidRuntime(28171): java.lang.RuntimeException: Unable to start 

activity ComponentInfo{com.neochat/com.neochat.Viewflip}:   android.view.InflateException: 

Binary XML file line #75: Error inflating class <unknown>

08-21 12:33:56.781: E/AndroidRuntime(28171):    at 

android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)

08-21 12:33:56.781: E/AndroidRuntime(28171):    at 

android.app.ActivityThread.startActivityNow(ActivityThread.java:2023)

08-21 12:33:56.781: E/AndroidRuntime(28171):    at 

android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)

这里是视图翻转java的代码

        public class Viewflip extends Activity 
          {
        private ViewFlipper viewFlipper;
        private float lastX;

        @Override
        protected void onCreate(Bundle savedInstanceState) 
        {
                     super.onCreate(savedInstanceState);
                     setContentView(R.layout.gallery);
                     viewFlipper = (ViewFlipper) findViewById(R.id.view_flipper);
        }



        // Method to handle touch event like left to right swap and right to left swap
        public boolean onTouchEvent(MotionEvent touchevent) 
        {
                     switch (touchevent.getAction())
                     {
                            // when user first touches the screen to swap
                             case MotionEvent.ACTION_DOWN: 
                             {
                                 lastX = touchevent.getX();
                                 break;
                            }
                             case MotionEvent.ACTION_UP: 
                             {
                                 float currentX = touchevent.getX();

                                 // if left to right swipe on screen
                                 if (lastX < currentX) 
                                 {
                                      // If no more View/Child to flip
                                     if (viewFlipper.getDisplayedChild() == 0)
                                         break;

                                     // set the required Animation type to ViewFlipper
                                     // The Next screen will come in form Left and  
                     current Screen will go OUT from Right 
                                     viewFlipper.setInAnimation(this, 
                   R.anim.in_from_left);
                                     viewFlipper.setOutAnimation(this, 
                    R.anim.out_to_right);
                                     // Show the next Screen
                                     viewFlipper.showNext();
                                 }

                                 // if right to left swipe on screen
                                 if (lastX > currentX)
                                 {
                                     if (viewFlipper.getDisplayedChild() == 1)
                                         break;
                                     // set the required Animation type to ViewFlipper
                                     // The Next screen will come in form Right and 
                              current Screen will go OUT from Left 
                                     viewFlipper.setInAnimation(this, 
                            R.anim.in_from_right);
                                     viewFlipper.setOutAnimation(this, 
                            R.anim.out_to_left);
                                     // Show The Previous Screen
                                     viewFlipper.showPrevious();
                                 }
                                 break;
                             }
                     }
                     return false;
                   }

                   }

为下面的视图翻转提供我的xml文件..

         <?xml version="1.0" encoding="utf-8"?>
       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
           android:layout_height="match_parent"
            android:orientation="vertical" 

                >


         <ViewFlipper
          android:id="@+id/view_flipper"
            android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:layout_margin="6dip" >

         <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:gravity="center"
                android:orientation="vertical" >



                <ImageView
                    android:layout_marginTop="15dp"
                    android:id="@+id/imageView1"
                    android:layout_width="450dp"
                    android:layout_height="450dp"
                    android:src="@drawable/scene1" 
                    />

        </LinearLayout>

         <!--  Layout 2 for 2nd Screen -->

        <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:gravity="center"
                android:orientation="vertical" >



                <ImageView
                    android:layout_marginTop="15dp"
                    android:id="@+id/imageView1"
                    android:layout_width="450dp"
                    android:layout_height="450dp"
                    android:src="@drawable/scene2" 
                    />

        </LinearLayout>
          <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:gravity="center"
                android:orientation="vertical" >



                <ImageView
                    android:layout_marginTop="15dp"
                    android:id="@+id/imageView1"
                    android:layout_width="450dp"
                    android:layout_height="450dp"
                    android:src="@drawable/scene3" 
                    />

          </LinearLayout>


               </ViewFlipper>

          </LinearLayout>

0 个答案:

没有答案