简体   繁体   中英

LinearLayout inside a RelativeLayout not working

I'm trying to layout an android page with a header, footer and body.

I'm using a LinearLayout nested in a RelativeLayout. My issue is only the first TextView inside the Linear is appearing. I'm guessing the other 2 controls are behind the text.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

  <TextView
    android:id="@+id/header"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:textSize="28dp"
    android:text="kernmobile"
    />

  <Button
    android:id="@+id/footer"
    android:layout_width="200dip"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="Login"
    />

  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/header"
    android:layout_above="@id/footer">

    <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textSize="24dp"
      android:text="Login" />

    <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textSize="20dp"
      android:text="Username" />

    <EditText
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textSize="20dp"
      />

  </LinearLayout>

</RelativeLayout>

Any ideas?

This is a super common issue. You seem to want a vertical orientation for your LinearLayout , but the default is horizontal . You need to specify it explicitly:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/header"
    android:layout_above="@id/footer"
    android:orientation="vertical">

LinearLayout's default orientation is Horizontal. Add android:orientation="vertical" and you should see what you want.

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