垂直线性布局不';不显示,但在java xml文件中显示

垂直线性布局不';不显示,但在java xml文件中显示,java,xml,android-linearlayout,xml-layout,Java,Xml,Android Linearlayout,Xml Layout,我在学校刚开始Java编程,我的第一项任务是使用xml布局重新创建我正在开发的应用程序,而不是以编程方式创建元素。我有两个独立的线性布局,我想出现,一个是水平的,一个是垂直的。我所有的水平布局看起来都不错,但每当我尝试添加垂直布局时,它都会添加,但不会显示。在emulator中,我可以看出它正在被添加,因为水平LLs被推来推去 下面是一个代码示例: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:androi

我在学校刚开始Java编程,我的第一项任务是使用xml布局重新创建我正在开发的应用程序,而不是以编程方式创建元素。我有两个独立的线性布局,我想出现,一个是水平的,一个是垂直的。我所有的水平布局看起来都不错,但每当我尝试添加垂直布局时,它都会添加,但不会显示。在emulator中,我可以看出它正在被添加,因为水平LLs被推来推去

下面是一个代码示例:

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/randomButton"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight=".5"
        android:text="DERP" />
</LinearLayout>

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

    <TextView
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="HIIIII" />

    <Button
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Badoop" />
</LinearLayout>

</LinearLayout>

有什么建议吗?谢谢


David

我将您的代码复制到eclipse布局视图中

  • 您省略了结束LinearLayout元素。可能只是在复制粘贴中遗漏了它,但如果没有,请添加它
  • “0dip”宽度给了我错误。当我切换到“包装内容”时,效果很好
  • 文本视图未显示,因为黑地和文本均为黑色
以下是文本视图和按钮:

   <TextView
    android:layout_width="wrap_content"
    android:textColor="@color/white"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="HIIIII" />

    <Button
    android:layout_width="wrap_content"
    android:textColor="@color/black"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="Badoop" />

谢谢,实际上是0dip把事情搞砸了。一旦我设置了一个实际的宽度,它工作得很好。谢谢你的回复:D