Question

I am trying to display some radio buttons and a drop down list in a layout of a tab, but only the first three radio buttons are displaying. Can anyone help me with this? Here is my layout code. When I run it on the emulator, the second tab only displays three radio buttons, but it's supposed to display three radio buttons, a text view, and a drop down list of the musketeers :(

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="fill_parent">
<TabHost android:id="@+id/tabhost"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
    <LinearLayout android:layout_width="match_parent"
        android:id="@+id/linearLayout1" android:layout_height="fill_parent"
        android:orientation="vertical">
        <TabWidget android:layout_width="match_parent"
            android:layout_height="wrap_content" android:id="@android:id/tabs">                                                                         </TabWidget>
        <FrameLayout android:layout_width="match_parent"
            android:layout_height="fill_parent" android:id="@android:id/tabcontent">
            <LinearLayout android:layout_width="match_parent"
                android:layout_height="fill_parent" android:id="@+id/tab1">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:text="Choose a background colour"
                    android:id="@+id/textView"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="10dp"
                    android:textSize="25dp"
                    android:textIsSelectable="true" />

            </LinearLayout>


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

                <RadioGroup
                    android:id="@+id/rgGroup1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <RadioButton android:id="@+id/RB1" android:text="Button1" />
                    <RadioButton android:id="@+id/RB2" android:text="Button2" />
                    <RadioButton android:id="@+id/RB3" android:text="Button3" />
                </RadioGroup>
                <TextView
                    android:id="@+id/txtRadio"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="RadioGroup: Nothing picked"
                    />
                <Spinner
                    android:id="@+id/spnMusketeers"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="2dp"
                    />

                </LinearLayout>
            <LinearLayout android:layout_width="match_parent"
                android:layout_height="fill_parent" android:id="@+id/tab3">
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Add a tab"
                    android:id="@+id/bAddTab" />

                </LinearLayout>
        </FrameLayout>
    </LinearLayout>
   </TabHost>

</LinearLayout>
Was it helpful?

Solution

Default orientation for LinearLayout is horizontal, so you should add orientation attribute:

<LinearLayout 
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="fill_parent" 
  android:id="@+id/tab2">

OTHER TIPS

You just forgot to specify the orientation of your LinearLayouts, because otherwise it's treated as horizontal by default. It should be like this:

 <LinearLayout android:layout_width="match_parent"
               android:layout_height="fill_parent"
               android:id="@+id/tab1"
               android:orientation="vertical">

Please note, I've added android:orientation="vertical"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top