Riskhan
Riskhan

Reputation: 4470

some issue with RelativeLayout in my app

My app contains ListView and TextView. I want to arrange TextView to below of ListView. I tried with below code, but TextView disappeared.

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

 <ListView android:id="@+id/android:list" 
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" /> 

 <TextView  
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:layout_below="@+id/android:list"
  android:text="@string/hello"
 />
</RelativeLayout>

Thanks.

Upvotes: 0

Views: 117

Answers (6)

deepak Sharma
deepak Sharma

Reputation: 1641

Try this code

<?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:background="#ffffff"
>  
<ListView android:id="@+id/android:list" 
 android:layout_height="match_parent"  
 android:gravity="center"
 android:cacheColorHint="#ffffffff" 
 android:layout_width="match_parent" 
 android:layout_above="@+id/add_workout_all_workout_list"></ListView>

<TextView android:layout_width="wrap_content"      
 android:id="@+id/add_workout_all_workout_list" android:layout_height="wrap_content" 
 android:text="textView" android:layout_alignParentBottom="true"  
 android:layout_alignParentLeft="true"/>

</RelativeLayout>  

Upvotes: 1

josephus
josephus

Reputation: 8304

If you insist on using RelativeLayout, do the following:

  1. In your xml, declare first your TextView before your ListView (interchange declarations) - order is important when using RelativeLayout
  2. In your TextView, put android:layout_alignParentBottom="true"
  3. In your ListView, put android:layout_above="@android/your_text_views_id_here"
  4. Remove all other positioning properties.

Should work.

Upvotes: 0

Richa
Richa

Reputation: 3193

U can place Textview below listview by 2 ways.

  1. Take Relative layout and fix the height of listview and place textview below it.
  2. Take LinearLayout and give weight in horizontal orientation.

Hope u get what i say.

Upvotes: 0

CjS
CjS

Reputation: 2047

Try LinearLayout as below. I think this will produce what you're after. This layout will always put the TextView below the list at the bottom of the view.

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

<ListView android:id="@+id/android:list" 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_weight="1" /> 

<TextView  
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content" 
   android:text="@string/hello"
  />
</LinearLayout>

Upvotes: 2

C--
C--

Reputation: 16558

Try replacing your XML with this

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

 <ListView android:id="@+id/android:list" 
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_weight="1" /> 

 <TextView  
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:layout_below="@+id/android:list"
  android:text="@string/hello"
 />
</LinearLayout>

You don't want to use the relative layout at all. If you need it specifically, simply replace the LinearLayout with it.

Upvotes: 3

Yugandhar Babu
Yugandhar Babu

Reputation: 10349

You used fill_parent for both width and height of listview as below. So it will occupy entire screen. So that the Text view is invisible. Please change it to fixed height according to your device resolution.

<ListView android:id="@+id/android:list" 
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" /> 

Replace fill_parent with 100px or other in below line and try once

  android:layout_height="fill_parent" /> 

Upvotes: 0

Related Questions