Hi I am using the following code for flipping the images along with the description.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/view_flipper"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"
                android:src="@drawable/lightning" />

            <TextView
                style="@style/ImageTitle"
                android:text="@string/lightning" />
        </RelativeLayout>

       <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

         <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"
                android:src="@drawable/color_baloons" />

            <TextView
                style="@style/ImageTitle"
                android:text="@string/color_baloons" />
        </RelativeLayout> 

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"
                android:src="@drawable/natural_wall" />

            <TextView`enter code here`
                style="@style/ImageTitle"
                android:text="@string/natural_wall" />
        </RelativeLayout>
   </ViewFlipper>
</RelativeLayout>

If I run the above code the app is crashing. But if I remove the ImageView from the second RelativeLayout the code is working fine. I am pasting the logcat also here.

    04-02 01:58:54.683: E/AndroidRuntime(1166): FATAL EXCEPTION: main
    04-02 01:58:54.683: E/AndroidRuntime(1166): java.lang.RuntimeException: Unable to start             activityComponentInfo{com.javatechig.viewflipper/com.javatechig.viewflipper.ViewFlipperSampleActivity}: android.view.InflateException: Binary XML file line #34: Error inflating class <unknown>
    04-02 01:58:54.683: E/AndroidRuntime(1166):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
    04-02 01:58:54.683: E/AndroidRuntime(1166):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
    04-02 01:58:54.683: E/AndroidRuntime(1166):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
    04-02 01:58:54.683: E/AndroidRuntime(1166):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
    04-02 01:58:54.683: E/AndroidRuntime(1166):     at android.os.Handler.dispatchMessage(Handler.java:99)
    04-02 01:58:54.683: E/AndroidRuntime(1166):     at android.os.Looper.loop(Looper.java:137)
    04-02 01:58:54.683: E/AndroidRuntime(1166):     at android.app.ActivityThread.main(ActivityThread.java:5103)
    04-02 01:58:54.683: E/AndroidRuntime(1166):     at java.lang.reflect.Method.invokeNative(Native Method)
    04-02 01:58:54.683: E/AndroidRuntime(1166):     at java.lang.reflect.Method.invoke(Method.java:525)
    04-02 01:58:54.683: E/AndroidRuntime(1166):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    04-02 01:58:54.683: E/AndroidRuntime(1166):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    04-02 01:58:54.683: E/AndroidRuntime(1166):     at dalvik.system.NativeStart.main(Native Method)
    04-02 01:58:54.683: E/AndroidRuntime(1166): Caused by: android.view.InflateException: Binary XML file line #34: Error inflating class <unknown>

The same code is working for device type 3.7 and when run int 5.4 it is not working. The minSdkVersion is 18.

Thank You

有帮助吗?

解决方案 2

I had to increase the VM heap while creating the emulator. It was by default 16 and I tried with 64 and it worked.

其他提示

ok i think the problem is with this in your second RelativeLayout

 <RelativeLayout
   android:layout_width="fill_parent"
     android:layout_height="fill_parent" 
     android:src="@drawable/color_baloons" >

Remove the

android:src="@drawable/color_baloons"

and try as you did in others

   <RelativeLayout
       android:layout_width="fill_parent"
         android:layout_height="fill_parent"   >
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top