其他分享
首页 > 其他分享> > 当我改变我的XML RelativeLayout android的顺序时app崩溃了

当我改变我的XML RelativeLayout android的顺序时app崩溃了

作者:互联网

标题说明了一切,我的应用程序每次更改布局视图时都会崩溃,我需要按钮位于最顶部,而imageView1位于最底部,iv_photo位于两者之间.所以我尝试拿我的xml按钮并将其移动到底部,我的应用程序崩溃,我不改变代码或任何东西,所有我只是做的是移动代码.继承我的代码

DOESNT CRASH

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DashboardActivity" >

    <ImageView
        android:id="@+id/iv_photo"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp" />

    <Button
        android:id="@+id/btn_crop"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignLeft="@+id/iv_photo"
        android:layout_alignTop="@+id/iv_photo"
        android:text="@string/Nothing" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="105dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:scaleType="fitXY"
        android:src="@drawable/whitestrip" />

</RelativeLayout>

崩溃了

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DashboardActivity" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="105dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:scaleType="fitXY"
        android:src="@drawable/whitestrip" />

    <ImageView
        android:id="@+id/iv_photo"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp" />

    <Button
        android:id="@+id/btn_crop"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignLeft="@+id/iv_photo"
        android:layout_alignTop="@+id/iv_photo"
        android:text="@string/Nothing" />

</RelativeLayout>

这是我在LogCat中遇到的错误

05-01 13:49:15.632: E/AndroidRuntime(32148): FATAL EXCEPTION: main
05-01 13:49:15.632: E/AndroidRuntime(32148): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.atmebeta/com.example.atmebeta.DashboardActivity}: java.lang.ClassCastException: android.widget.ImageView
05-01 13:49:15.632: E/AndroidRuntime(32148):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
05-01 13:49:15.632: E/AndroidRuntime(32148):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-01 13:49:15.632: E/AndroidRuntime(32148):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-01 13:49:15.632: E/AndroidRuntime(32148):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-01 13:49:15.632: E/AndroidRuntime(32148):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-01 13:49:15.632: E/AndroidRuntime(32148):    at android.os.Looper.loop(Looper.java:123)
05-01 13:49:15.632: E/AndroidRuntime(32148):    at android.app.ActivityThread.main(ActivityThread.java:3687)
05-01 13:49:15.632: E/AndroidRuntime(32148):    at java.lang.reflect.Method.invokeNative(Native Method)
05-01 13:49:15.632: E/AndroidRuntime(32148):    at java.lang.reflect.Method.invoke(Method.java:507)
05-01 13:49:15.632: E/AndroidRuntime(32148):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
05-01 13:49:15.632: E/AndroidRuntime(32148):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
05-01 13:49:15.632: E/AndroidRuntime(32148):    at dalvik.system.NativeStart.main(Native Method)
05-01 13:49:15.632: E/AndroidRuntime(32148): Caused by: java.lang.ClassCastException: android.widget.ImageView
05-01 13:49:15.632: E/AndroidRuntime(32148):    at com.example.atmebeta.DashboardActivity.onCreate(DashboardActivity.java:106)
05-01 13:49:15.632: E/AndroidRuntime(32148):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-01 13:49:15.632: E/AndroidRuntime(32148):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)

解决方法:

我以前见过这样的东西.

尝试运行干净的构建,然后再次运行您的应用程序.

在窗口栏上转到“项目” – > “清洁”

清理所有解决方案然后它应该是好的.

标签:android,xml,android-activity,z-index
来源: https://codeday.me/bug/20190723/1509781.html