Tobias Moe Thorstensen
Tobias Moe Thorstensen

Reputation: 8981

Align a layout to the top of another layout in order to make a status bar

I have a layout like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#e4e8ed"
android:gravity="top" >

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/app"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="0px"
    android:orientation="vertical"
    android:padding="0px" >

    <include
        android:id="@+id/tabBar"
        layout="@layout/tab" />

    <Button
        android:id="@+id/nist"
        android:layout_width="match_parent"
        android:layout_height="67dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="3dp"
        android:layout_marginLeft="3dp"
        android:layout_marginRight="3dp"
        android:layout_marginTop="3dp"
        android:background="@drawable/ready"
        android:textColor="#FFFFFF" />

    <ListView
        android:id="@+id/lastCases"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2.08"
        android:longClickable="true" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="7dp"
    android:layout_below="@id/app"
    android:background="@drawable/dropshadow_custom" >

    <TextView
        android:id="@+id/error"
        style="@style/AudioFileInfoOverlayText"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="120dp"
        android:gravity="center"
        android:text="No Cases"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#D6D8D9"
        android:textSize="40dp" />
</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/app"
    android:background="#000000"
    android:gravity="bottom"
    android:orientation="vertical" >
</LinearLayout>

</RelativeLayout>

I try to align the last LinearLayout on top of the layout which holds the ListView by using this tag: android:layout_alignTop="@+id/app" But it doesn't seem to work. How can accomplish this?

Many Thanks!

Upvotes: 0

Views: 13678

Answers (2)

Cechinel
Cechinel

Reputation: 707

You can set "layout_below" on the first layout targeting to the last layout.

The code is that, I put a button inside the top layout as an exemple (Obs: In your listview you should use 0dp in layout_weight cause you already use layout_weight ^^) :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/parent"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:background="#e4e8ed"
     android:gravity="top" >

     <LinearLayout
          android:id="@+id/app"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="0px"
          android:orientation="vertical"
          android:layout_below="@+id/top"
          android:padding="0px" >

     <Button
          android:id="@+id/nist"
          android:layout_width="match_parent"
          android:layout_height="67dp"
          android:layout_gravity="center_horizontal"
          android:layout_marginBottom="3dp"
          android:layout_marginLeft="3dp"
          android:layout_marginRight="3dp"
          android:layout_marginTop="3dp"
          android:textColor="#FFFFFF" />

     <ListView
          android:id="@+id/lastCases"
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="2.08"
          android:longClickable="true" />
</LinearLayout>

<LinearLayout
     android:layout_width="fill_parent"
     android:layout_height="7dp"
     android:layout_below="@+id/app" >

     <TextView
          android:id="@+id/error"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_marginTop="120dp"
          android:gravity="center"
          android:text="No Cases"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:textColor="#D6D8D9"
          android:textSize="40dp" />
</LinearLayout>

<LinearLayout
     android:id="@+id/top"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_alignParentLeft="true"
     android:layout_alignParentRight="true"
     android:background="#000000"
     android:gravity="bottom"
     android:orientation="vertical" >

    <Button 
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"    
          android:text="Top"
/>

Upvotes: 1

Lars
Lars

Reputation: 1043

Without any content a Layout with layout_width="wrap_content" and layout_height="wrap_content" is not shown as its width and height have a value of 0! Even if you have set some background color nothing will appear! You either have to add some content to the layout or you have to define another layout dimension. The position of your layout with android:layout_alignTop="@+id/app" should be correct. Hope that helps.

Upvotes: 1

Related Questions