开发者

Directly Nesting Linear Layouts only shows the first child view

I am trying to nest two Linear Layouts as direct children of another Linear Layout. Eventually the intention is for these two layouts to be nested within a ViewFlipper, so each of the two Linear Layouts will be flipped in and out of the screen.

The Layouts work fine until I nest the two Linear Layouts within a parent element, in which case only the first widget in the first child is displayed. So I have something like this:

<LinearLayout (parent)...
  <LinearLayout (child1)...
   <child1's Widgets... <---only the first widget here is being shown

  <LinearLayout (child2)...
   <child2's widgets...

I have no idea why this could be happening. Can anybody shed any light??

Full code:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFFFFF">

        <TextView  
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:textSize="22sp"
            android:layout_gravity="center"
            android:gravity="center" 
            android:text="Hello, is this a great app?"
            android:textColor="#000000"
            android:layout_marginBottom="10dip"
            android:layout_marginTop="8dip"/>

        <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
            <Button
                android:id="@+id/btnYes"
                android:text="Yes"
                android:textSize="20sp"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginBottom="7dip"
                android:layout_marginLeft="4dip"
                android:layout_marginRight="4dip"/>
            <Button
                android:id="@+id/btnNo"
                android:text="No"
                android:textSize="20sp"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginBottom="7dip"
                android:layout_marginLeft="4dip"
                android:layout_marginRight="4dip"/>
        </LinearLayout>

        <!--  <ViewFlipper
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"> 
             -->

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

                <LinearLayout <!-- ONLY THE CONTENT FROM HERE IS BEING SHOWN -->
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">

                    <TextView
                    android:layout_width="0px" 
                    android:layout_height="wrap_content"
                    android:text="Lat:"
                    android:textSize="16sp"
                    android:layout_weight="1"
                    android:layout_marginLeft="12dip"/>
                    <TextView
                    android:id="@+id/lblLat"  
                    android:layout_width="0px" 
                    android:layout_height="wrap_content"
                    android:text=""
                    android:textSize="16sp"
                    android:layout_weight="3"
                    android:gravity="right"
                    android:layout_marginRight="12dip"/>
                </Linea开发者_如何学运维rLayout> <!--NO MORE CONTENT Is SHOWN AFTER HERE -->

                <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">   
                    <TextView
                    android:layout_width="0px" 
                    android:layout_height="wrap_content"
                    android:text="Lon:"
                    android:textSize="16sp"
                    android:layout_weight="1"
                    android:layout_marginLeft="12dip"/>
                    <TextView
                    android:id="@+id/lblLon"  
                    android:layout_width="0px" 
                    android:layout_height="wrap_content"
                    android:text=""
                    android:textSize="16sp"
                    android:layout_weight="3"
                    android:gravity="right"
                    android:layout_marginRight="12dip"/>

                </LinearLayout>

                <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">   
                    <TextView
                    android:layout_width="0px" 
                    android:layout_height="wrap_content"
                    android:text="Number of satellites:"
                    android:textSize="16sp"
                    android:layout_weight="3"
                    android:layout_marginLeft="12dip"/>
                    <TextView
                    android:id="@+id/lblSats"  
                    android:layout_width="0px" 
                    android:layout_height="wrap_content"
                    android:text=""
                    android:textSize="16sp"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:layout_marginRight="12dip"/>

                </LinearLayout>

                <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">   
                    <TextView
                    android:layout_width="0px" 
                    android:layout_height="wrap_content"
                    android:text="Signal To Noise:"
                    android:textSize="16sp"
                    android:layout_weight="3"
                    android:layout_marginTop="25dip"
                    android:layout_marginLeft="12dip"/>
                    <TextView
                    android:id="@+id/lblSNR"  
                    android:layout_width="0px" 
                    android:layout_height="wrap_content"
                    android:text=""
                    android:textSize="16sp"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:layout_marginTop="25dip"
                    android:layout_marginRight="12dip"/>

                </LinearLayout>

                <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">

                    <TextView
                    android:id="@+id/lblAddresses"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text=""
                    android:textSize="16sp"
                    android:layout_marginLeft="12dip"
                    android:minLines="3"/>

               </LinearLayout>

            </LinearLayout>

            <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

            <TextView
                    android:id="@+id/lblAbout"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Stuff About App"
                    android:textSize="16sp"
                    android:layout_marginLeft="12dip"
                    android:minLines="3"/>

            </LinearLayout>


        <!--  </ViewFlipper> -->

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <Button
                    android:id="@+id/btnLookup"
                    android:text="LookUp"
                    android:textSize="18sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="20dip"
                    android:paddingTop="1dip"
                    android:paddingBottom="5dip"
                    android:layout_alignParentBottom="true"
                    android:layout_marginBottom="8dip"
                    android:layout_marginLeft="8dip" />

            <Button
                    android:id="@+id/btnQuit"
                    android:text="Quit"
                    android:textSize="18sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentRight="true"
                    android:padding="20dip"
                    android:paddingTop="1dip"
                    android:paddingBottom="5dip"
                    android:layout_marginBottom="8dip"
                    android:layout_marginRight="8dip" />

        </RelativeLayout>

    </LinearLayout>


Make sure to have on all your LinearLayout tags an android:orientation property.

<LinearLayout
  ..
  android:orientation="vertical|horizontal">
...
</LinearLayout>

If you want to display the child components in vertical, you need to indicate it explicitly because by default it is set to horizontal.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜