-1

I created a new Android Project in eclipse and trying to add Tab Widget but I am getting an error saying "No orientation specified, and the default is horizontal. This is a common source of bugs when children are added dynamically." I tried putting android:orientation="horizontal"> Can anyone tell me how to resolve this problem?

Code is:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.checktabs.MainActivity$PlaceholderFragment" >

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="43dp" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <LinearLayout  <-error->
                    android:id="@+id/tab1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </LinearLayout>

                <LinearLayout   <-error->
                    android:id="@+id/tab2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </LinearLayout>

                <LinearLayout   <-error->
                    android:id="@+id/tab3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </LinearLayout>
            </FrameLayout>
        </LinearLayout>
    </TabHost>

</RelativeLayout>

2 Answers2

1

In your case, just remove all Linear Layouts from Frame layout and try to add your tab dynamically from activity.

View this example for more details. Android TabWidget Example

Pragnesh Ghoda シ
  • 8,318
  • 3
  • 25
  • 40
0

Due to lint rules, the android:orientation attribute is mandatory for all LinearLayout items in xml layouts.

See https://android-review.googlesource.com/#/c/49060/2/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/InefficientWeightDetector.java

You just need to add whatever orientation you will need (most likely, vertical).

matiash
  • 54,791
  • 16
  • 125
  • 154
  • I don't think so. According to the documentation it says default is horizontal. Check: http://developer.android.com/reference/android/widget/LinearLayout.html#attr_android%3aorientation So if we didn't add anything it should be horizontal. – Zusee Weekin May 23 '14 at 03:59
  • @ZuseeWeekin Yes, the default is horizontal. That is precisely why the warning was added: it most cases the orientation you want is vertical (i.e. one view below the other). – matiash May 23 '14 at 14:35