应用程序继续崩溃,因为我添加了我的ViewFlipper

时间:2016-02-27 20:56:03

标签: android android-layout

标题说了所有内容

这里是activity_main.xml代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/menuslide" >

<ViewFlipper
    android:id="@+id/flipper1"
    android:layout_width="fill_parent"
    android:layout_height="150dp"
    android:flipInterval="3000"
    android:inAnimation="@anim/slide_in_right"
    android:outAnimation="@anim/slide_out_left">


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

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="fitXY"
            android:id="@+id/imageView"
            android:src="@drawable/vp_1"
            android:layout_alignParentEnd="true" />

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

    </RelativeLayout>

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

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="fitXY"
            android:id="@+id/imageView2"
            android:src="@drawable/vp_2"
            android:layout_alignParentEnd="true" />

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

    </RelativeLayout>

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

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="fitXY"
            android:id="@+id/imageView3"
            android:src="@drawable/vp_3"
            android:layout_alignParentEnd="true" />

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

    </RelativeLayout>

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

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="fitXY"
            android:id="@+id/imageView4"
            android:src="@drawable/vp_4"
            android:layout_alignParentEnd="true" />

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

    </RelativeLayout>


</ViewFlipper>

<TableRow
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_below="@+id/flipper1"
    android:layout_alignParentEnd="true"
    android:id="@+id/tableRow">

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="105dp"
        android:layout_height="wrap_content"
        android:onClick="local"
        android:textSize="10sp"
        android:text="Track"
        android:id="@+id/button3" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="105dp"
        android:layout_height="wrap_content"
        android:onClick="miseenmarche"
        android:textSize="10sp"
        android:text="Activation"
        android:id="@+id/button5" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="105dp"
        android:layout_height="wrap_content"
        android:onClick="config"
        android:textSize="10sp"
        android:text="Configuration"
        android:id="@+id/button7" />
</TableRow>

<LinearLayout
    android:orientation="vertical"
    android:layout_width="75dp"
    android:layout_height="230dp"
    android:layout_marginTop="30dp"
    android:layout_alignParentEnd="true"
    android:layout_below="@+id/tableRow">

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:text=""
        android:background="@drawable/facebook_icon"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="7dp"
        android:id="@+id/button8" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="40dp"
        android:layout_height="45dp"
        android:text=""
        android:background="@drawable/tutoriel_icon"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="12dp"
        android:id="@+id/button9" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:text=""
        android:background="@drawable/faq_icon"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="12dp"
        android:id="@+id/button10" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:text=""
        android:background="@drawable/contact_icon"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="12dp"
        android:id="@+id/button11" />
</LinearLayout>

MainActivity.java:

  public Boolean active = false;
private Context context = this;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ViewFlipper flipper = (ViewFlipper) findViewById(R.id.flipper1);

    flipper.startFlipping();

    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

slide_in_right.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:fromXDelta="100%p"
       android:toXDelta="0"
       android:duration="5000"/>
</set>

slide_in_left.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:fromXDelta="0"
       android:toXDelta="-100%p"
       android:duration="500"/>
</set>

它看起来非常完美,但是当我启动应用程序时,我的应用程序一直在崩溃...如果有人可以帮助我这个

更新

02-27 22:37:36.448  12168-12168/? I/dalvikvm﹕ at com.acer.thewatcher.MainActivity.onCreate(MainActivity.java:29)
02-27 22:37:36.483  12168-12168/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.acer.thewatcher, PID: 12168
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.acer.thewatcher/com.acer.thewatcher.MainActivity}: android.view.InflateException: Binary XML file line #133: Error inflating class <unknown>
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2447)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2507)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5692)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #133: Error inflating class <unknown>
            at android.view.LayoutInflater.createView(LayoutInflater.java:626)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at com.acer.thewatcher.MainActivity.onCreate(MainActivity.java:29)
            at android.app.Activity.performCreate(Activity.java:5541)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2411)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2507)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5692)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at android.view.LayoutInflater.createView(LayoutInflater.java:600)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at com.acer.thewatcher.MainActivity.onCreate(MainActivity.java:29)
            at android.app.Activity.performCreate(Activity.java:5541)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2411)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2507)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5692)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.OutOfMemoryError
            at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
            at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:694)
            at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:519)
            at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:889)
            at android.content.res.Resources.loadDrawable(Resources.java:3382)
            at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
            at android.view.View.<init>(View.java:3715)
            at android.widget.TextView.<init>(TextView.java:926)
            at android.widget.Button.<init>(Button.java:108)
            at android.widget.Button.<init>(Button.java:104)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at android.view.LayoutInflater.createView(LayoutInflater.java:600)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at com.acer.thewatcher.MainActivity.onCreate(MainActivity.java:29)
            at android.app.Activity.performCreate(Activity.java:5541)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2411)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2507)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5692)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

内存不足异常会假设您在Activity中加载的图像太大或太多。尽量减少它们并仅提供合适的尺寸。

XML-inflate错误可能是由此引起的,但只有在修复第一个错误后才能检查。无论如何,你的XML-Layout是不完整的。 RelativeLayout永远不会关闭,但也许您只是错过了复制该部分。