每当我尝试在应用程序中将方向更改为横向时,我正在开发它崩溃。
用于纵向模式 RES /布局/ activity_main.xml中 用于横向模式 RES /布局脊/ activity_main.xml中
我正在使用线性布局,但是eclipse保持显示“此LinearLayout布局或其LinearLayout父级是无用的”。以下是风景模式的代码。请帮助。
<?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>
答案 0 :(得分:1)
在你的活动中使用你的宣言:
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;
}
}
答案 1 :(得分:0)
在清单文件中添加活动类, 如果你的android:targetSdkVersion =“12”或更少
android:configChanges="orientation|keyboardHidden">
如果您的android:targetSdkVersion =“13”或更多
android:configChanges="orientation|keyboardHidden|screensize">
答案 2 :(得分:0)
关于错误“此LinearLayout布局或其LinearLayout父级是无用的”
这是因为第二个LinearLayout确实没用,你可以删除它
<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">
将其更改为
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="15dip"
android:paddingBottom="15dip"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:orientation="vertical"
android:layout_gravity="center" >
并删除底部的</LinearLayout>
中的一个<
除非您在第二个linearlayout下面有另一个视图组,否则不会出现警告。
我认为这只是一个警告,而不是崩溃你的应用程序的主要问题
您应该再次查看logcat以检查应用程序崩溃的异常