android - 直接嵌套线性布局只显示第一个 subview

标签 android xml layout nested

我试图嵌套两个线性布局作为另一个线性布局的直接子级。最终的目的是将这两个布局嵌套在一个 ViewFlipper 中,因此两个线性布局中的每一个都将在屏幕内和屏幕外翻转。

布局工作正常,直到我将两个线性布局嵌套在一个父元素中,在这种情况下,仅显示第一个 子元素中的第一个 小部件。所以我有这样的东西:

<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>

最佳答案

确保在所有 LinearLayout 标签上都有一个 android:orientation 属性。

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

如果要以垂直显示子组件,则需要明确指出,因为默认设置为水平

关于android - 直接嵌套线性布局只显示第一个 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7149654/

相关文章:

Android:如何知道按钮是否被按下

结果之间有空格的 xmlstarlet

android - 如何创建具有 4 列的 TableLayout?

ios - 为什么我的 UIViewController 顶部有 20px 的间隙?

java - 在 doInBackground 中使用 OkHttpClient 时应用程序崩溃

如果 Android 应用程序闲置几个小时会自动退出

java - Xml解析为Java对象

Android:如何命名布局文件夹

android - 如何生成 33 字节压缩的 NIST P-256 公钥?

c# - Xml 序列化 - 忽略父节点