我正在为我的 CS 课程开发一个 Android 项目,我需要在其中输入模拟坐标。我想为方向和纵向指定不同的布局文件。我的文件夹中有一个layout
文件夹和一个layout-land
文件/res
夹。layout 文件夹中的 xml 文件和 layout-land 文件夹中的 xml 文件命名完全相同。我没有android:configChanges="orientation"
或没有android:screenOrientation="portrait"
为此特定活动设置 - 但是,我确实为其他活动设置了它。我也没有onConfigurationChanged
在这项活动中实施。
layout-land
从理论上讲,当方向随这些设置发生变化时,屏幕应该更改为指定的布局,对吗?
然而,这种情况并非如此。布局保持不变。
我试图通过给横向布局一个不同的布局ID来强制它改变android:id="@+layout/activity_mock_coor_land"
,然后做setContentView(R.layout.activity_mock_coor_land)"
。
但是,它给了我这个堆栈跟踪的错误:
AndroidRuntime(13964): FATAL EXCEPTION: main
AndroidRuntime(13964): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mixd.grounds.tour/com.mixd.grounds.tour.MockCoor}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030009 type #0x12 is not valid
AndroidRuntime(13964): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
AndroidRuntime(13964): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
AndroidRuntime(13964): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
AndroidRuntime(13964): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
AndroidRuntime(13964): at android.os.Handler.dispatchMessage(Handler.java:99)
AndroidRuntime(13964): at android.os.Looper.loop(Looper.java:123)
AndroidRuntime(13964): at android.app.ActivityThread.main(ActivityThread.java:4627)
AndroidRuntime(13964): at java.lang.reflect.Method.invokeNative(Native Method)
AndroidRuntime(13964): at java.lang.reflect.Method.invoke(Method.java:521)
AndroidRuntime(13964): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
AndroidRuntime(13964): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
AndroidRuntime(13964): at dalvik.system.NativeStart.main(Native Method)
AndroidRuntime(13964): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030009 type #0x12 is not valid
AndroidRuntime(13964): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874)
AndroidRuntime(13964): at android.content.res.Resources.getLayout(Resources.java:731)
AndroidRuntime(13964): at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
AndroidRuntime(13964): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
AndroidRuntime(13964): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
AndroidRuntime(13964): at android.app.Activity.setContentView(Activity.java:1647)
AndroidRuntime(13964): at com.mixd.grounds.tour.MockCoor.onCreate(MockCoor.java:21)
AndroidRuntime(13964): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
AndroidRuntime(13964): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
AndroidRuntime(13964): ... 11 more
我不太确定这意味着什么。它找不到我的布局layout-land
吗?
任何人都可以帮助解决这个问题吗?
编辑:清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mixd.grounds.tour" android:versionCode="1" android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library
android:name="com.google.android.maps"
android:required="true" />
<activity
android:name=".SplashScreen"
android:label="@string/title_activity_main"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MapsActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/title_activity_maps"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden"
android:label="@string/title_activity_main"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".Choice"
android:label="@string/title_activity_choice"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".MockCoor"
android:label="@string/title_activity_mock_coor" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".MockActivity"
android:label="@string/title_activity_mock"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".NextCoor"
android:label="@string/title_activity_next_coor" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".HistoryButton"
android:label="@string/title_activity_history_button" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".DisplayHistory"
android:label="@string/title_activity_display_history" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
</manifest>