尝试使用字符串限定符在 list 文件中设置方向
android:screenOrientation="@string/orientation"
在 4.0 asus 平板电脑上工作,但在 2.1 wildfire 和 4.1 Galaxy S 上都失败。 问题实际上是链接到资源,如果输入肖像,它就可以工作。
我尝试更改平板电脑中使用的限定符以在手机上进行测试。这意味着所有设备都使用完全相同的代码、资源和布局。所以它不可能是拼写错误或构建问题。但它在手机而不是平板电脑上仍然失败。这似乎是 android 中的另一个错误。
给出以下错误,logcat 中没有任何内容
Installation error: INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION
Please check logcat output for more details.
Launch canceled!
list 部分
<activity
android:name=".MainActivity"
android:screenOrientation="@string/orientation"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
我知道我可以通过编程来完成。但是野火还有一个问题,不能马上重启。相反,它会等待设置 View 等。其他设备不会发生这种情况。
用谷歌搜索并发现其他一些人使用这些方法,但他们似乎没有发现任何问题。 http://capdroid.wordpress.com/2012/07/21/different-screen-orientation-on-different-screen-size
谢谢
最佳答案
我有同样的问题,我已经使用整数值而不是字符串值解决了它,并在“onCreate”方法中设置了方向:
例子:
值/strings.xml
<resources>
<integer name="orientation">1</integer>
...
values-sw600dp/strings.xml
<resources>
<integer name="orientation">0</integer>
</resources>
然后,在您的 onCreate 中:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(getResources().getInteger(R.integer.orientation));
每个方向都有一个整数值,有关详细信息,请参阅此页面:http://developer.android.com/reference/android/R.attr.html#screenOrientation
关于android - 某些设备忽略 Manifest 中的字符串资源,Parse Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11703742/