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.
Related
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">
i have a problem with my scrollview...
my xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ScrollView android:id="#+id/scrollView1" android:layout_width="wrap_content" android:layout_height="match_parent">
<RelativeLayout [...]>
<TextView [...]></TextView>
<Spinner [...]></Spinner>
<Button [...]></Button>
<ImageButton [...]></ImageButton>
<TextView [...]></TextView>
<TableLayout [...]>
<TableRow [...]>
<TextView [...]></TextView>
<TextView [...]></TextView>
<TextView [...]></TextView>
</TableRow>
<TableRow [...]>
<AutoCompleteTextView [...]></AutoCompleteTextView>
<AutoCompleteTextView [...]></AutoCompleteTextView>
<Spinner [...]></Spinner>
</TableRow>
</TableLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
When i try to scroll in my App it wont work... what did i do wrong?
i deleted the properties from the elements. if you need them to solve the problem i can add them.
i did it to get a better overview.
thanks,
prexx
Try adding the ScrollView as the parent. Swich place with LinearLayout.
And dont forget to add the following on your ScrollView instead of the LinearLayout:
xmlns:android="http://schemas.android.com/apk/res/android"
And layout_widht and layout_height of the ScrollView should be set to "fill_parent"
This is my code which uses ScrollView in a calendar I made, could help you:
<?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="fill_parent"
android:fillViewport="true">
<LinearLayout
android:id="#+id/layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="#+id/dayView" android:text="Day" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/>
<Button android:id="#+id/weekView" android:text="Week" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/>
<Button android:text="Month" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:enabled="false"/>
<Button android:id="#+id/eventsView" android:text="Events" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/prevMonth"
android:src="#drawable/calendar_left_arrow_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
<Button
android:id="#+id/currentMonth"
android:layout_weight="0.6"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="#drawable/calendar_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<ImageView
android:id="#+id/nextMonth"
android:src="#drawable/calendar_right_arrow_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
</LinearLayout>
<LinearLayout
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content" android:layout_height="20dp" android:text="Week" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/monday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/tuesday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/wednesday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/thursday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/friday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/saturday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/sunday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<ViewFlipper
android:id="#+id/flipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<GridView
android:id="#+id/weeks"
android:numColumns="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="8"
android:scrollbars="none">
</GridView>
<GridView
android:id="#+id/calendar"
android:numColumns="7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="none">
</GridView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<GridView
android:id="#+id/weeks2"
android:numColumns="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="8"
android:scrollbars="none">
</GridView>
<GridView
android:id="#+id/calendar2"
android:numColumns="7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="none">
</GridView>
</LinearLayout>
</ViewFlipper>
</LinearLayout>
<LinearLayout
android:id="#+id/bottom_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/create_event"
android:text="Create event"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Try adding android:fillViewport="true" to your scrollView.
The height of your scrollView should probably be either match_parent or fill_parent aswell.
If the ScrollView content doesn't take up the whole space, it will behave as a normal layout, i.e. non-scrollable.
If you still need the ScrollView to fill the entire screen (but still not scroll since there is not enough content) you could do as Nicholas Magnussen mentioned and add android:fillViewport="true"
Please change to android:layout_width="wrap_content" android:layout_height="wrap_content"
to fill parent.
Thank you
I have a layout problem, the idea is that the buttons and text dont show
<?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="#ffffff" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#5094c5"
android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingTop="8dp" >
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/logo" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Set the height and width in the xml layout file to what they should be when they are visible but initially, in code, get a reference to them and make them invisible. Then, when needed, you can make them visible (in code).
Maybe better try with RelativeLayout. This seems to be too nested and too much complicated than it suppose to be.
You can give setVisibility() property to button and textview in layout.
I am trying to display an EditText and a Button horizontally and below of them I want to display a List(ListView). I have try this but it seems it's only sees the first Layout and nothing else after.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dip"
> <LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="4"> <EditText
android:id="#+id/search_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
/>
<Button
android:id="#+id/search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go"
android:layout_weight="1"
/> </LinearLayout> <!-- <EditText
android:id="#+id/testedit_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
/>
--> <ListView android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/text1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="#+id/text2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall" /></LinearLayout>
I have also tried and the commented line (EditText) and also it is not showing me anything...
Any idea?
Thanks!
Add
layout_weight="1"
into your horizontal layout.
And you will need to add similar lines in the TextViews at the bottom if you want to see those also.
Your current problem is that you set that one to fill_parent, so when it gets to the ListView, there is no space available.
you are using two nested LinearLayout with fillParent... you are doing it wrong.
Why don't you use RelativeLayout?
Try this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dip">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:weightSum="4"
android:layout_height="wrap_content">
<EditText
android:id="#+id/search_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3" />
<Button
android:id="#+id/search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go"
android:layout_weight="1" />
</LinearLayout> <!-- <EditText android:id="#+id/testedit_txt" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="3" /> -->
<ListView
android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"/>
<TextView
android:id="#+id/text1"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content"
android:text="qwe" />
<TextView
android:id="#+id/text2"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_height="wrap_content"
android:text="qwe" />
</LinearLayout>
I'm assuming that you want the EditText and Button at the top, the two TextViews at the bottom, and the ListView to fill the available space in the middle. If that's the case then you need to tweak your layout_height's and add a android:layout_weight="1" to your ListView:
<?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" android:padding="1dip">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:weightSum="4"
android:layout_height="wrap_content">
<EditText android:id="#+id/search_txt" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="3" />
<Button android:id="#+id/search_button" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Go"
android:layout_weight="1" />
</LinearLayout> <!-- <EditText android:id="#+id/testedit_txt" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="3" /> -->
<ListView android:id="#+id/android:list" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1" />
<TextView android:id="#+id/text1" android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content" />
<TextView android:id="#+id/text2" android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_height="wrap_content" />
</LinearLayout>
Try this .... worked for me :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pagelayout">
<FrameLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/content">
<ListView android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
<LinearLayout android:layout_height="wrap_content"
android:id="#+id/button_layout"
android:layout_width="fill_parent" android:gravity="center" android:layout_above="#+id/content">
<Button android:id="#+id/search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go"
android:layout_weight="1"
/>
<EditText>
android:id="#+id/search_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
</EditText>
</LinearLayout>
</RelativeLayout>
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.