0

Whenever I try to change the the orientation to landscape in the app I'm developing it crashes.

for portrait mode res/layout/activity_main.xml for landscape mode res/layout-land/activity_main.xml

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>
4

3 回答 3

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;
    }

}
于 2013-08-03T16:04:21.283 回答
0

在清单文件中添加这个活动类,如果你的 android:targetSdkVersion="12" 或更少

android:configChanges="orientation|keyboardHidden">

如果你的 android:targetSdkVersion="13" 或更多

 android:configChanges="orientation|keyboardHidden|screensize">
于 2013-08-03T15:59:55.360 回答
0

关于错误“This LinearLayout layout or its LinearLayout parent is useless”
这是因为第二个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>底部的一个

除非您在第二个线性布局下方有另一个视图组,否则不会出现警告..
我认为这只是一个警告,而不是导致您的应用程序崩溃的主要问题,
您应该再次查看 logcat 以检查导致应用程序崩溃的异常

于 2014-05-21T08:54:45.463 回答