I want to place a textview on the right of a layout and on the left of a layout, but they keep stacking ontop of each other:
<LinearLayout
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent" android:orientation="horizontal">
<TextView
android:id="#+id/lefttext"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:text="Symbol"/>
<TextView
android:id="#+id/righttext"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:text="Price"/>
</LinearLayout>
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="fill_parent"
android:orientation="horizontal"
>
<TextView
android:id="#+id/left_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Symbol"
/>
<TextView
android:id="#+id/right_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Price"
/>
</LinearLayout>
Why are you specifying 0dip for the height on these?
For symbols on sides:
<?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/left_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dip"
android:gravity="left"
android:text="Symbol"
/>
<TextView
android:id="#+id/right_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dip"
android:gravity="right"
android:text="Price"
/>
</LinearLayout>
And done with a 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"
>
<TextView
android:id="#+id/left_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip"
android:layout_alignParentLeft="true"
android:text="Code"
/>
<TextView
android:id="#+id/right_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:layout_toRightOf="#+id/left_text"
android:gravity="right"
android:text="Company Name"
/>
</RelativeLayout>
With LinearLayout, just put an empty TextView with the weight between them:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/lefttext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Symbol"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<TextView
android:id="#+id/righttext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Price"/>
</LinearLayout>
Use android:layout_alignParentLeft="true" and android:layout_alignParentRight="true" on view inside RelaytiveLayout like this
<?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="wrap_content"
>
<TextView
android:id="#+id/left_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left|center_vertical"
android:text="Symbol"
/>
<TextView
android:id="#+id/right_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right|center_vertical"
android:text="Price"
/>
</RelativeLayout>
Alternatively you can use TableLayout with stretchColumn set to stretch the second column to the size of parent.
Related
I need set textView10 at center of vertical and horizontal. I've tried a lot without results... I tried with gravity options but nothing.. any idea? textView10 is within scrollview. Thanks for help.
<?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="#000000"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="151dp"
android:layout_height="fill_parent"
android:textSize="15pt" />
<ScrollView
android:id="#+id/scrollView10"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#000000" >
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:gravity="center_vertical"
android:textAlignment="center"
android:textColor="#ffffff"
android:textSize="13sp"
android:textStyle="italic" />
</ScrollView>
</LinearLayout>
<Button
android:id="#+id/button10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chiudi" />
</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:background="#000000"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="151dp"
android:layout_height="fill_parent"
android:textSize="15pt" />
<ScrollView
android:id="#+id/scrollView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#000000" >
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="320dp"
android:background="#000000"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="13sp"
android:text="Hi What is your name"
android:textStyle="italic" />
</ScrollView>
</LinearLayout>
<Button
android:id="#+id/button10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chiudi" />
Change your outer layout to RelativeLayout and position yout ScrollView at the parent center. Position other elements in relation to one in center
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:id="#+id/TextView1"
android:layout_width="151dp"
android:layout_height="fill_parent"
android:textSize="15pt" />
<ScrollView
android:id="#+id/scrollView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#000000" >
<TextView
android:id="#+id/textView10"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:gravity="center_vertical"
android:textAlignment="center"
android:textColor="#ffffff"
android:textSize="13sp"
android:textStyle="italic" />
</ScrollView>
</RelativeLayout>
Put the TextView inside of a RelativeLayout, and put that RelativeLayout inside of the ScrollView.
Then, set android:layout_centerInParent="true" within the TextView
I have a layout with a view text views, a table and then some buttons at the bottom.
I wanted the buttons to always be at the bottom regardless of the height of the table so I changed the layout to relative so I could do this.
However this mashed all the textviews and the table into one line. So I put these in a LinearLayout within the RelativeLayout which I thought would fix the problem. Problem now is that only the first TextView and the buttons at the bottom show up. Everything else is missing.
Here is the xml code I am using to define this layout:
<?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:layout_margin="4dip"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<TextView
android:id="#+id/view_meal_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Spaghetti Bolognaise"
android:textSize="25sp" />
<TextView
android:id="#+id/view_meal_type"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Dinner"
android:textSize="16sp" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/view_day_calories"
android:text="#string/calories_label"
android:textSize="18sp" />
<TextView
android:id="#+id/view_day_calories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="#string/calories_today_value"
android:textSize="18sp" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="10dip"
android:background="#color/hr" />
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:stretchColumns="0,1,2" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/meal_table_ingred_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ingredient"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/meal_table_quantity_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/quantity"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/meal_table_calories_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/calories"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="1.0" >
<Button
android:id="#+id/edit_meal_button"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/edit_meal_label" />
<Button
android:id="#+id/favourite_meal_button"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/favourite_meal_label" />
</LinearLayout>
</RelativeLayout>
Thanks for your help!
Change
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
to
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">
How to make spinner to fill empty place in left side?
android:layout_width="fill_parent" does not help.
XML layout:
<Spinner
android:id="#+id/spn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text1" />
<TextView
android:id="#+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text2" />
</LinearLayout>
I would make use of a Relative Layout and Linear Layout combination to achieve this,
<?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" >
<Spinner
android:id="#+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/lin_layout" />
<LinearLayout
android:id="#+id/lin_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="asd" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fgdas" />
</LinearLayout>
</RelativeLayout>
The Output,
Andro solution's above is perfect as per your need .....
but if data in text view is dynamic and may be too long then can try android:weightSum="1" here
<?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:weightSum="1"
>
<Spinner
android:id="#+id/spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".8" />
<LinearLayout
android:id="#+id/lin_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight=".2" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text2" />
</LinearLayout>
</LinearLayout>
i have a fragment with a RelativLayout that holds a TextView at the top, a LinearLayout (which is filled dynammically with CheckBoxes) in the middle and a Button at the bottom.
The problem is that i need scrolling if too many CheckBoxes are added. The Button is alligned using the attribut layout_alignParentBottom and is displayed at the top of the screen. This attribut is not working with Scrollview.
<?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="vertical">
<TextView
android:id="#+id/show_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="25sp"
android:gravity="center"
android:padding="10dp" />
<LinearLayout
android:id="#+id/hold_check_boxes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_below="#+id/show_content" />
<Button android:id="#+id/save"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="#string/save"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
any suggestions?
EDIT: with ScrollView
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/topLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/show_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="25sp"
android:gravity="center"
android:padding="10dp"
android:background="#drawable/bottom_border" />
<LinearLayout
android:id="#+id/hold_check_boxes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_below="#+id/show_content" />
<Button android:id="#+id/save"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="#string/save"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</ScrollView>
You can do like this without taking as parent. The only thing you have to do is take Linearlayout in ScrollView.
<?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" >
<TextView
android:id="#+id/show_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:textColor="#color/black"
android:textSize="25sp" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/save"
android:layout_below="#+id/show_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" >
<LinearLayout
android:id="#+id/hold_check_boxes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
<Button
android:id="#+id/save"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/save" />
</RelativeLayout>
Update:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/show_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:textColor="#color/black"
android:textSize="25sp" />
<LinearLayout
android:id="#+id/hold_check_boxes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/show_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical" />
<Button
android:id="#+id/save"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="#+id/hold_check_boxes"
android:layout_centerHorizontal="true"
android:text="#string/save" />
</RelativeLayout>
</ScrollView>
I finally managed to get my list to display properly (http://stackoverflow.com/questions/5662277/how-to-line-up-intger-output-in-custom-android-dialog).
Now I am trying to add a button below the list. What happens is that when the list is too big the button doesn't show.
The list is scrollable but that's it.
Also, the scrollbar covers some of the data.
This is the main XML file:
<?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/lloPlayerNames" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="#+id/tvwPlayer1Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer2Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer3Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer4Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_margin="2dp"/>
</LinearLayout>
<ListView android:id="#+id/lvwScores" android:layout_below="#id/lloPlayerNames"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<Button android:id="#+id/btnOK "
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_below="#id/lvwScores" android:layout_weight="1"
android:text="OK" android:layout_centerHorizontal="true" />
</RelativeLayout>
This is the one for the rows:
<?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="wrap_content" android:orientation="horizontal">
<TextView android:id="#+id/tvwPlayer1Score" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer2Score" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer3Score" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer4Score" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
</LinearLayout>
I tried changing the main to a linear layout but that made it even worse! The list looked like it had been on a crash-diet and was super-thin.
Tried:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="#+id/lloPlayerNames" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="#+id/tvwPlayer1Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer2Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer3Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer4Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginRight="2dp"/>
</LinearLayout>
<Button android:id="#+id/btnOK"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="OK" android:layout_centerHorizontal="true"
layout_alignParentBottom="true"/>
<ListView android:id="#+id/lvwScores" android:layout_above="#id/btnOK" android:layout_below="#id/lloPlayerNames"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_weight="1"/>
</RelativeLayout>
and what I get is:
when I try:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">>
<LinearLayout android:id="#+id/lloPlayerNames" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="#+id/tvwPlayer1Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer2Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer3Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer4Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginRight="2dp"/>
</LinearLayout>
<ListView android:id="#+id/lvwScores"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_weight="1"/>
<Button android:id="#+id/btnOK"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="OK" android:layout_centerHorizontal="true"
layout_alignParentBottom="true"/>
</LinearLayout>
I get:
Following is what I do on a couple of my apps with a ListView or a ScrollView, where I also have a fixed button or LinearLayout of buttons at the bottom. The "magic" is to set android:layout_weight="1" in the ListView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView
android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fastScrollEnabled="true" />
<TextView
android:id="#+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No Quotes!" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="My Button" />
</LinearLayout>
You should put the button before the list and then use the layout_above property on the list element to position it above the button. Also add layout_alignParentBottom="true" to your button.
Like so:
<?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/lloPlayerNames" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/tvwPlayer1Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView
android:id="#+id/tvwPlayer2Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView
android:id="#+id/tvwPlayer3Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView
android:id="#+id/tvwPlayer4Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_margin="2dp"/>
</LinearLayout>
<Button android:id="#+id/btnOK"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_below="#id/lvwScores" android:layout_weight="1"
android:text="OK" android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
/>
<ListView
android:id="#+id/lvwScores"
android:layout_below="#id/lloPlayerNames"
android:layout_above="#id/btnOK"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
Try adding a attribute android:below="#id/lvwScores" to the Button in main xml, this will place the Button below the ListView.
See this tutorial for more about RelativeLayout.