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

时间:2013-08-01 00:17:07

标签: java xml android-linearlayout xml-layout

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

以下是代码示例:

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

有什么建议吗?谢谢,

大卫

1 个答案:

答案 0 :(得分:0)

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

  • 您没有关闭LinearLayout元素。可能只是在复制粘贴中错过了它,但如果没有,请添加它。
  • “0dip”宽度给了我错误。当我切换到“wrap_content”时,它工作正常。
  • 未显示Textview,因为背景和文字都是黑色。

这是textview和按钮:

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