I've a two line listview with the following XML for the row:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip"
android:gravity="center_vertical"
>
<TextView
android:id="#+id/designation"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="2"
android:id="#+id/orderedValue"
android:gravity="bottom"
android:singleLine="true"
android:ellipsize="marquee"
/>
</LinearLayout>
what I want is to have the first row (designation) to be at the exact vertical center of the row, and the second row (orderedValue) just below it
I've been trying with several combinations of LinearLayout/Relative layout, gravity vs layout_gravity for the TextViews to no avail
Any help/pointers here?
I'd make a blank View above the first TextView which can share the same weight as the text below it.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip"
>
<View
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
/>
<TextView
android:id="#+id/designation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:id="#+id/orderedValue"
android:singleLine="true"
android:ellipsize="marquee"
/>
</LinearLayout>
If I were you I'll try to put designation TextView inside a LinearLayout and use android:layout_gravity to center it. I tried this in my activity and it centered the first TextView. However, I'm not sure if it will work in your list.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip"
android:gravity="center_vertical" >
<LinearLayout
android:id="#+id/layout"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/designation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="18sp"
android:textStyle="bold"
android:text="designation" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="2"
android:id="#+id/orderedValue"
android:gravity="bottom"
android:singleLine="true"
android:ellipsize="marquee"
android:text="orderedValue" />
</LinearLayout>
iTurki, thanks for the input, but I just solved it before reading your solution.
I switched to a relative layout and changed some parameters, most importantly adding: android:layout_centerVertical="true".
here is my final layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent"
android:padding="6dip"
>
<TextView
android:id="#+id/designation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="19sp"
android:layout_centerVertical="true"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/orderedValue"
android:singleLine="true"
android:layout_below="#id/designation"
android:paddingTop="6dip"
android:textColor="#33B5E5"
android:textSize="13sp"
/>
</RelativeLayout>
Thank you both for your interest!
Related
i have a Fragment with following Layout:
<?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="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:background="#ffffff"
android:id="#+id/dateItemRow"
>
<TextView
android:id="#+id/timeField"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textStyle="bold"
android:layout_marginTop="3dp"
android:paddingBottom="0dp"
android:textColor="#5d6265"
android:textSize="16sp" />
<LinearLayout
android:id="#+id/rowBackground"
android:layout_width="3dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#33b5e6"
>
<TextView
android:id="#+id/seperator"
android:layout_width="2dp"
android:layout_height="fill_parent"
android:textColor="#000000"
android:text=""
/>
</LinearLayout>
<CheckBox
android:id="#+id/mycheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:button="#drawable/custom_checkbox_design"
/>
</LinearLayout>
How you (hopefully) see this is a Layout where on the Left site is a Time Field then kind a Border to separate the TimeField from the CheckBox. What i'm looking for is to set all of them to Center.
Actual everything is on the Left Site.
All this is in a ListView what i have described like this:
<?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:background="#e8e8e8" >
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#e8e8e8" >
</ListView>
</LinearLayout>
I really have NO Idea how i can get this. THX for your HELP!!
Try adding
android:gravity="center"
to your outer LinearLayout.
I have a problem with relativelayout where its children could use layout_below and layout_weight to set its percentage height.
For example, we have a relative layout and inside of it we have three linear layouts with textviews. Now, I would like to set for three of them (linearlayouts) 25,50,25 % of height of total height of relative layout. How could I accomplish it?
I found a solution for weight_sum and and relativelayout (CLICK), but it doesn't use layout_below.
How can I fix this?
I tried to add additional linearlayout inside of all linearlayouts, but then I am unable use layout_below.
Here is concept picture idea:
Here is my code:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/linlay_leftcol_notification_header" >
<LinearLayout
android:id="#+id/linlay_leftcol_clock_theday"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tv_theday"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/theday"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="#+id/linlay_leftcol_clock_thetime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linlay_leftcol_clock_theday" >
<TextView
android:id="#+id/tv_thetime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/thetime"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="#+id/linlay_leftcol_clock_thenumber_themonth_theyear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linlay_leftcol_clock_thetime" >
<TextView
android:id="#+id/tv_thenumberofday_themonth_theyear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/thenumberofday_themonth_theyear"
android:textColor="#FFFFFF" />
</LinearLayout>
</RelativeLayout>
Try 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="match_parent"
android:background="#ff00ff"
android:orientation="vertical">
<RelativeLayout
android:layout_weight="1"
android:background="#ffff00"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Hello 1"
android:textColor="#000000"
android:textSize="15dp" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="2"
android:background="#00ffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Hello 2"
android:textColor="#000000"
android:textSize="15dp" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:background="#ffff00"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Hello 3"
android:textColor="#000000"
android:textSize="15dp" />
</RelativeLayout>
</LinearLayout>
Check out 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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".15"
android:background="#android:color/background_dark"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rel_1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#A52A2A" >
<TextView
android:id="#+id/tv_theday"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="1st layout"
android:textColor="#FFFFFF" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#8B008B" >
<TextView
android:id="#+id/tv_theday"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="2ndlayout"
android:textColor="#FFFFFF" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#00008B" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="3rd layout"
android:textColor="#FFFFFF" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/rel_side"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".75"
android:background="#ff0000" >
<TextView
android:id="#+id/tv_theday"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="side layout"
android:textColor="#FFFFFF" />
</RelativeLayout>
</LinearLayout>
You may use either weight or relative layout properties. You can make that 25,50,25 like this...you align the parent left first textview, align parent right, other textview, and the remaining textview's you align to the left of the first one and to the right of the last one.
Use Table Layout and inside that, you put your textviews. There is an attribute, "stretch column", for table layout. There you can mention the size as " 0,2,1" like that...
I want to add a textview right at the end of another textview, ie not in next line, but where previous textview ends, in xml file. Just like:
| <TextView1><TextView2> |
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbb |
My xml file:
<?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="horizontal" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
android:ellipsize="none"/>
<TextView
android:id="#+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="bbb" />
</LinearLayout>
but text "bbb" is not shown. Can anyone help?
Use following.
<?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="horizontal" >
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="none"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
/>
<TextView
android:id="#+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="bbb" />
</LinearLayout>
<?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" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
android:ellipsize="none"/>
<TextView
android:id="#+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="bbb" />
</LinearLayout>
use weight sum .....
I have provided both 50% space you can change as per your requirement.......
<?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="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
android:ellipsize="none"
android:layout_weight=".5"/>
<TextView
android:id="#+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="bbb"
android:layout_weight=".5" />
</LinearLayout>
as per requirement ......
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
android:ellipsize="none"
/>
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bbb"
android:layout_alignRight="#id/textView"
/>
</LinearLayout>
</HorizontalScrollView>
This is because you have provided android:ellipsize="none" as none and giving a very long text to textView.
just provide android:ellipsize="end" and you will be able to see second textView.
Use a RelativeLayout and have your "aaaa..." text view align to the left of the "bbb" textview. You can either remove maxLines or set it to some other value if you want multiple lines.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/date"
android:ellipsize="none"
android:maxLines="1"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="bbb" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="fill">
<TextView android:id="#+id/textView"
android:text="bbb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_alignParentRight="true" />
<TextView android:id="#+id/date"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/textView"
android:singleLine="true"
android:ellipsize="none" />
</RelativeLayout>
it's simple use one textView and inside your cod use append method and add some space before your second text :)
I have two LinearLayout
One contains a EditText with a patch9 image as a speech bubble and another with a TextView and ImageView
When I try typing into the EditText is begins to expand towards the right hand side then starts to reduce the width of the second LinearLayout (crushing the image)
XML is
<?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:background="#color/white"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:orientation="vertical" >
<EditText
android:id="#+id/summaryMessage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/greeting_bubble_white"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<ImageView
android:id="#+id/summaryImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/picture_frame" />
<TextView
android:id="#+id/summaryText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="10dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Looks like this
Any ideas?
its expanding since you have specified that layout_width of your LinearLayout should be "wrap_content", you should specify a fixed dimension with dps so it doesn't expand beyond.
Alternative use the weight tag
try out this modification:
<?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:background="#color/white"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:layout_weight="0.7">
<EditText
android:id="#+id/summaryMessage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/greeting_bubble_white"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="right"
android:orientation="vertical" >
<ImageView
android:id="#+id/summaryImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/picture_frame" />
<TextView
android:id="#+id/summaryText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="10dp" />
</LinearLayout>
however I would suggest more that you use this one:
<?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:background="#color/white"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="#+id/summaryMessage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:background="#drawable/greeting_bubble_white"
android:gravity="center" />
<TextView
android:id="#+id/summaryText"
android:layout_weight="0.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="10dp" />
</LinearLayout>
and that you use compound drawables on your summaryText here is a link that should help you: Using Compund Drawables
Use a relative layout, the layout editor is in fact pretty good so use it to position your views
I want create a layout, with a horizontal LinearLayout(s) on top and bottom, a ListView fill in middle.
How can I define the main.xml.
I tried to create a layout with horizontal LinearLayout on top, TextView on bottom, a ListView fill in middle; is ok. But after I modified the bottom TextView to LinearLayout, the bottom LinearLayout disappear.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:textSize="12px"
android:text="something here"
android:layout_width="50px"
android:layout_height="wrap_content"
/>
<TextView
android:textSize="12px"
android:text="something here"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
>
<ListView
android:id="#+id/listbody"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12px"
android:text="50%"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12px"
android:text="50%"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Anybody can tell advise?
Please help.
Try containing the whole set in a RelativeLayout:
<?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" >
<LinearLayout
android:id="#+id/top_linear_layout_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom_linear_layout_id"
android:layout_below="#id/top_linear_layout_id" />
<LinearLayout
android:id="#+id/bottom_linear_layout_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
</LinearLayout>
</RelativeLayout>
Edited with sizing stuff.
Here's what you're looking for. Estel's on the right track with the RelativeLayout (although it can be done with a LinearLayout, I think the RelativeLayout approach is cleaner, though) but the layout is out of order Nevermind, check Estel's comment which proved me wrong. :) You should first define your header, align it to the top; next, define your footer, and align it to the bottom; finally, declare your ListView, give it a height of fill_parent, and set it to layout above the footer and below the header:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:alignParentTop="true"
>
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:alignParentBottom="true"
>
</LinearLayout>
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/footer"
android:layout_below="#id/header"
/>
</RelativeLayout>
The problem would be that you are defining both of them relative to the size of the content they contain, but if the combined content of both is bigger than the screen then one of them will have to overlap the other one, you would be better to define the layout_height using an absolute measurement in a linear layout
Thanks all for your advice and direction of RelativeLayout. I can fix it now.
I have to define the footer LinearLayout before the ListView, and define ListView as android:layout_alignParentTop="true" and android:layout_above="#id/footer"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:textSize="12px"
android:text="something here"
android:layout_width="50px"
android:layout_height="wrap_content"
/>
<TextView
android:textSize="12px"
android:text="something here"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="#+id/footer"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12px"
android:text="50%"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12px"
android:text="50%"
/>
</LinearLayout>
<ListView
android:id="#+id/tablebody"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#id/footer"
/>
</RelativeLayout>
</LinearLayout>
This will definitely solve your problem:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:textSize="12sp"
android:text="something here"
android:layout_width="50dp"
android:layout_height="wrap_content"/>
<TextView
android:textSize="12sp"
android:text="something here"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</HorizontalScrollView>
<ListView
android:id="#+id/listbody"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12sp"
android:text="50%"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12sp"
android:text="50%"/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>