Reputation: 1625
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>
Upvotes: 0
Views: 4317
Reputation: 1
about the error "This LinearLayout layout or its LinearLayout parent is useless"
it's because the second LinearLayout is indeed useless, you can remove it
<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">
just change it to
<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" >
and remove one of </LinearLayout>
in the bottom
unless you have another viewgroup below the second linearlayout, the warning will not appear..
and i think it's only a warning, not the main issue which crashes your app
you should look again at the logcat to check what exception makes the app crashes
Upvotes: 0
Reputation: 366
use in your Manifest at your activity:
android:configChanges="orientation"
try to use then:
@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;
}
}
Upvotes: 1
Reputation: 7082
Add this with activity class in manifest file, If your android:targetSdkVersion="12" or less
android:configChanges="orientation|keyboardHidden">
if your android:targetSdkVersion="13" or more
android:configChanges="orientation|keyboardHidden|screensize">
Upvotes: 0