风景定向崩溃的Android应用程序 [英] Landscape Orientation crashing Android app
本文介绍了风景定向崩溃的Android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当我尝试在应用程序中将方向更改为横向时,我正在开发的应用程序就会崩溃.
Whenever I try to change the the orientation to landscape in the app I'm developing it crashes.
用于纵向模式 RES/布局/activity_main.xml 用于风景模式 res/layout-land/activity_main.xml
for portrait mode res/layout/activity_main.xml for landscape mode res/layout-land/activity_main.xml
我正在使用Linear-Layout,但是日食显示此LinearLayout布局或其LinearLayout父级是无用的".下面是风景模式的代码.请帮忙.
I am using Linear-Layout but eclipse keeping showing "This LinearLayout layout or its LinearLayout parent is useless" . Below is the code of Landscape Mode. Please Help.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="15dip"
android:orientation="horizontal" >
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:paddingLeft="20dip"
android:paddingRight="20dip">
<TextView
android:text="@string/main_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dip"
android:textSize="24.5sp" />
<TableLayout >
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:stretchColumns="*">
<TableRow>
<Button
android:id="@+id/button1"
android:text="@string/continue_label" />
<Button
android:id="@+id/button2"
android:text="@string/new_game_label" />
</TableRow>
<TableRow>
<Button
android:id="@+id/button3"
android:text="@string/about_label" />
<Button
android:id="@+id/button4"
android:text="@string/exit_label" />
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
推荐答案
在您的活动清单中使用:
use in your Manifest at your activity:
android:configChanges="orientation"
然后尝试使用:
@Override
public void onConfigurationChanged(Configuration newConfig) {
Display display = ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
AddArticleActivity.DISPLAYROTATION = display.getRotation();
if (youractivity.DISPLAYROTATION == Surface.ROTATION_90 || youractivity.DISPLAYROTATION == Surface.ROTATION_270) {
do LANDSCAPE;
} else {
do PORTRAIT;
}
}
这篇关于风景定向崩溃的Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文