0

i am developing a simple app in Android. Whenever i change orientation to landscape one of my buttons get lost when i run APP on MOBILE device but my landscape view works fine with Andriod Simulator on PC. Other then this , APP works fine on Mobile Device.I am using TABLE LAYOUT for the landscape orientation. Below is my code please check where is the problem. Also ECLIPSE shows that "This LinearLayout layout or its LinearLayout parent is useless" why is that.

res/layout/activity_sudoku.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="30dip"
    android:orientation="horizontal" >
    <LinearLayout
    android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="25dip"
        android:text="@string/main_title" />

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/continue_label" />

    <Button
        android:id="@+id/button2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"

        android:layout_marginTop="21dp"
        android:text="@string/new_game_label" />

    <Button
        android:id="@+id/button3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"

        android:layout_marginTop="20dp"
        android:text="@string/about_label" />

    <Button
        android:id="@+id/button4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="29dp"
        android:text="@string/exit_label" />
</LinearLayout>
</LinearLayout>

(FOR LANDSCAPE VIEW)res/layout-land/activity_sudoku.xml

<?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>
Stefan
  • 5,203
  • 8
  • 27
  • 51
Abhishek
  • 1,585
  • 2
  • 12
  • 15
  • i have tested ur xml.both working fine.where is the problem? – TheFlash Aug 05 '13 at 05:02
  • @Pratik when i run app on my android simulator it work fine but when i run app on my andriod mobile , in landscape mode it still hides one of my buttons. – Abhishek Aug 05 '13 at 05:10

1 Answers1

0

Well, you have 2 nested LinearLayout. In this situation, one will be useless as it contains nothing but the second LinearLayout. Simply remove one.

Reduce the paddingLeft and paddingRight of the LinearLayout to see if it helps.

Btw, the structure you build is really complicate for this simple view. To get the best performance on low devices, avoid using too many nested objects.

Cheers,

Long Dao
  • 1,341
  • 4
  • 15
  • 33
  • thanx... but my app fine only on simulator , on mobile device problem still exist. – Abhishek Aug 05 '13 at 04:51
  • I am not sure but can you double check if you set both vertical mode and horizontal mode for this activity in you manifest file? – Long Dao Aug 05 '13 at 04:53
  • the only change that i done in my manifest file coding is this "android:configChanges="orientation|keyboardHidden"" – Abhishek Aug 05 '13 at 05:13