Прямое вложение линейных макетов показывает только первое дочернее представление - PullRequest
1 голос
/ 22 августа 2011

Я пытаюсь вложить два линейных макета как прямых потомков другого линейного макета.В конечном итоге предполагается, что эти два макета будут вложены в ViewFlipper, поэтому каждый из двух линейных макетов будет отображаться на экране и выходить из него.

Макеты работают нормально, пока я не вложу два линейных макета в родительский элемент, в этом случае отображается только виджет first в дочернем элементе first .Итак, у меня есть что-то вроде этого:

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

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

Я понятия не имею, почему это может происходить.Кто-нибудь может пролить свет ??

Полный код:

    <?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"/>
                </LinearLayout> <!--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>

1 Ответ

4 голосов
/ 22 августа 2011

Убедитесь, что на всех ваших тегах LinearLayout имеется свойство android:orientation.

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

Если вы хотите отобразить дочерние компоненты в vertical, вам нужно указать это явно, потому что по умолчанию он установлен на horizontal.

...