2013-08-01 45 views
0

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

下面的代码示例:

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

有什么建议?谢谢,

大卫

回答

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

谢谢,这实际上这是它搞乱了0dip。一旦我将它设置为实际宽度,它就可以正常工作。谢谢你的回应:D – DaveyDaVinci

相关问题