将纵向更改为横向时,Android应用程序强制关闭
以下是我的LogCat错误:将纵向更改为横向时,Android应用程序强制关闭,android,android-layout,android-view,android-xml,Android,Android Layout,Android View,Android Xml,以下是我的LogCat错误: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jc.jcpremiere/com.jc.jcpremiere.activity2}: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.os.Bundle instead
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jc.jcpremiere/com.jc.jcpremiere.activity2}: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.os.Bundle instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/aboutview. Make sure other views do not use the same id.
每当我把手机从纵向切换到横向时,我都会收到这个。我有/layout
和/layout land
的布局,其中只包含一个显示图像的视图,但在纵向上,它可以被压缩和缩放,并且位于中心内部
,在横向上它是fitxy
这是我的肖像布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rellayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.jc.jcpremiere.TouchImageView
android:id="@+id/aboutview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:adjustViewBounds="true"
android:background="@color/White"
android:scaleType="centerInside" />
</RelativeLayout>
还有我的风景
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativelayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/aboutview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:scaleType="fitXY" />
</RelativeLayout>
您的com.jc.jcpremere.TouchImageView
和ImageView
类都有android:id=“@+id/aboutview”
android:id
必须是唯一的,因此没有两个组件可以具有相同的android id。只需将一个Android id更改为其他id即可解决问题
另外,对于纵向和横向模式,请使用
TouchImageView
或ImageView
——每种模式的视图组件类型不同。您的ImageView类型正在从potrait模式更改为横向模式。Potrait使用ImageView,而横向使用TouchImageView。因此,findViewById()方法在横向模式中引用了错误的视图对象。尝试在java类中将imageView的对象更改为TouchImageView,然后我猜您的potrait模式将崩溃。是否有一种方法可以在横向和纵向上使用imageView,在内部使用TouchImageView center?