Elad Benda Elad Benda - 4 months ago 18
Java Question

why cannot i see a textView above another view in relative layout?

I have this xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp" >

<TextView
android:id="@+id/errorMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/pointsText"
android:visibility="gone"/>

<TextView
android:id="@+id/pointsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/offers_list"
android:text="you have 100 points"
android:visibility="visible"/>



<ListView
android:id="@+id/offers_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
android:dividerHeight="0dp"
android:divider="#00000000"/>




</RelativeLayout>


Yet I cannot see pointsText in my eclipse graphical previewer.

What am I missing?

Answer

You have

android:layout_above="@+id/offers_list"

for your TextView but you don't have any positioning for your ListView. Since RelativeLayouts place their children at the top-left by default, your ListView would be at the top and there would be nowhere above it to place your TextView.

Try removing that property from your TextView and add

android:layout_below="@id/pointsText"

on your ListView.

I just tested this and it does work. I can see the pointsText TextView above the list. So, you will want to do something different with your error TextView or you will quite possibly have the same issue with that when you want to change its visibility.

A bit off-topic

RelativeLayout doesn't have an orientation property so that doesn't do you any good but doesn't do you any real harm either.