简体   繁体   中英

Vertical linear layout doesn't show up, but horizontal does in java xml file

I've just started Java programming in school, and my first assignment is to recreate an app I was working on using an xml layout instead of programmatically creating the elements. I have two separate linear layouts I want to appear, one is horizontal and one is vertical. All of my horizontal layouts appear fine, but whenever I try to add a vertical one, it adds but does not show up. In the emulator, I can tell it's being added because the horizontal LLs are pushed around.

Here's an example of the code:

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

Any suggestions? Thanks,

David

I copied your code into eclipse layout view.

  • You left off the closing LinearLayout element. Probably just missed it in copy paste, but if not, add it.
  • The "0dip" width gave me errors. When I switched to "wrap_content" it worked fine.
  • The Textview isn't showing because the blackground and text are both black.

Here's the textview and button:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM