LinearLayout doesn't fill tablerow even width fill_parent is called - android

I have a linearLayout inside a tableRow, this linearLayout contains a chart that i would like to display for my app.
I read some thread saying that the child of the tableRow not need to specify its width and height, so I did it, but the chart is not displayed. If I specify the linearLayout to be width=fill_parent and height=200dp, then the linearlyLayout is only fill 1/3 of the tableRow.
<?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" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Record"
android:textSize="18dp"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="Name:"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:ems="10"
android:singleLine="true" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="Date:"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="#+id/editRecordDate"
android:layout_width="0dp"
android:layout_weight="0.7"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="#+id/tableRow9"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/soundaomplitude_graphViewLinearLayout"
android:paddingTop="4dip" > //if I specify nothing then nothing is displayed, if I set width = fill_parent and height = 200dp, then only 1/3 of the space is occupied
</LinearLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow10"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/saveEditRecord"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="Save" />
<Button
android:id="#+id/deleteEditRecord"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="Delete" />
<Button
android:id="#+id/cancelEditRecord"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight=".3"
android:text="Cancel" />
</TableRow>
</TableLayout>
</ScrollView>

I found out just set the weight = 1(or any number) for the linearLayout
<LinearLayout
android:id="#+id/soundaomplitude_graphViewLinearLayout"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_weight="1"
android:paddingTop="4dip" />

It seems that a TableRow acts as a LinearLayout, hence nesting one right inside a TableRow seems redundant. In Eclipse also, it says, that it is "useless". Therefore, you can just include your view (any view) directly inside the TableRow, instead of the LinearLayout. If it is not showing, then, there is probably some other problems.

Read again on how TableLayout manages its content. Specifically note that it disregards the layout_width of child views.

Related

TextView alignment in the TableRow

There are two TableRows in the TableLayout, and each TableRow contains two TextViews:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" >
<TextView
android:id="#+id/textTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textTitle"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="63dp"
android:layout_marginRight="10dp" >
<TextView
android:id="#+id/textHall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textPrice"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp" />
</TableRow>
</TableLayout>
If textHall contains a short Word, textTitle (Some Text) located at the correct position:
But if textHall contains a long Second Word, before textTitle (Some Text) appears a large indentation:
What is the reason?
Thanks.
You should give weight for your layouts and rows. I adapted your code. Here is the one that should be.
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:weightSum="2" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:orientation="horizontal" >
<TextView
android:id="#+id/textTime"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="10:30" />
<TextView
android:id="#+id/textTitle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:text="Some Text" />
</LinearLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="63dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:weightSum="2" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:orientation="horizontal" >
<TextView
android:id="#+id/textHall"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Some Word" />
<TextView
android:id="#+id/textPrice"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:text="200" />
</LinearLayout>
</TableRow>
You can put any margin value for your second row as you wish.
Hope this may help.
Your textHall and textTime both fall into same column and the width of that column is set to the width of textHall(as this is having more width) as a result your textTime textview's width is increasing when you increase text in textHall.

How to make the last TableRow visible?

Picture of the android interface: http://tinypic.com/view.php?pic=avht6w&s=6
As seen in the picture above I want a small borders at the bottom and top of the white listView. The problem is, as I set the tableRow to be android:paddingBottom="20dp" the border never gets displayed at the bottom. It seems like, if the listviews height is big enough, nothing else after it will get displayed (See code example below to understand).
I have tested some different approaches to solve the problem, one is setting the paddingBottom attribute in the next TableRow (the borders tableRow) but it will only work if the listView's height is exact of the screens height and not to big.
Why do I set the listView's height to a fixed number like 415dp? Well, it is due to another problem I do not know how to solve. If I for example set the listViews height to fill_parent the background will only cover the number of items in the list. I always want the lists background to be filled down to 20dp from the bottom of the interface.
If anyone has some ideas how I can managed to display the border at the bottom and always have the lists background visible, even if it is not filled with items, please post your ideas! /thanx alot!
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/orginalbild"
android:gravity="center|top"
android:stretchColumns="1"
android:weightSum="1.0"
android:fillViewport="true">
<TableRow
android:background="#000000"
>
<TextView
android:layout_marginTop="0.15dp"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#999999"
android:layout_weight="1">
</TextView>
</TableRow>
<TableRow
android:background="#999999"
>
<TextView
android:background="#999999"
android:id="#+id/show_task_feedback_title"
android:layout_width="0dip"
android:layout_height="28dp"
android:layout_weight="0.8"
android:text="#string/LatestFeedbackTitle"
android:textColor="#ffffff"
android:textSize="17dp"
android:shadowColor="#FFFFFF"
android:layout_marginBottom="0.15dp"
android:textAppearance="?android:attr/textAppearanceMedium">
</TextView>
<TextView
android:layout_width="0dip"
android:layout_height="28dp"
android:layout_gravity="center"
android:layout_weight="0.08" >
</TextView>
<Button
android:id="#+id/latest_feedback_help_button"
android:layout_width="0dip"
android:layout_height="28dp"
android:layout_gravity="center"
android:background="#drawable/help_button"
android:layout_weight="0.12"
android:layout_marginBottom="0.15dp"
/>
</TableRow>
<TableRow
android:background="#212421">
<TextView
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#ffffff"
android:layout_marginTop="0.15dp"
android:layout_weight="1">
</TextView>
</TableRow>
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25" />
</TableRow>
<TableRow
android:paddingLeft="24dp"
android:paddingRight="24dp"> <--------THE BLACK BRODER AT THE TOP OF THE LISTVIEW
<TextView
android:background="#000000"
android:layout_width="0dip"
android:layout_height="0.5dp"
android:layout_weight="1" >
</TextView>
</TableRow>
<TableRow
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:paddingBottom="20dp" <------(paddingBottom attribute which causes the problem)
>
<ListView
android:background="#ffffff"
android:id="#+id/bookmarks_list"
android:layout_width="0dip"
android:layout_height="415dp"
android:gravity="left"
android:layout_weight="1"
/>
</TableRow>
<TableRow> <---THE BLACK BRODER AT THE BOTTOM OF THE LISTVIEW(not being displayed)
<TextView
android:background="#000000"
android:layout_width="0dip"
android:layout_height="0.5dp"
android:layout_weight="1" >
</TextView>
</TableRow>
</TableLayout>
See if this helps.
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/orginalbild"
android:fillViewport="true"
android:gravity="center|top"
android:orientation="vertical"
android:stretchColumns="1"
android:weightSum="1.0" >
<TableRow android:background="#000000" >
<TextView
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_marginTop="0.15dp"
android:layout_weight="1"
android:background="#999999" >
</TextView>
</TableRow>
<TableRow android:background="#999999" >
<TextView
android:id="#+id/show_task_feedback_title"
android:layout_width="0dip"
android:layout_height="28dp"
android:layout_marginBottom="0.15dp"
android:layout_weight="0.8"
android:background="#999999"
android:shadowColor="#FFFFFF"
android:text="#string/LatestFeedbackTitle"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff"
android:textSize="17dp" >
</TextView>
<TextView
android:layout_width="0dip"
android:layout_height="28dp"
android:layout_gravity="center"
android:layout_weight="0.08" >
</TextView>
<Button
android:id="#+id/latest_feedback_help_button"
android:layout_width="0dip"
android:layout_height="28dp"
android:layout_gravity="center"
android:layout_marginBottom="0.15dp"
android:layout_weight="0.12"
android:background="#drawable/help_button" />
</TableRow>
<TableRow android:background="#212421" >
<TextView
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="0.15dp"
android:layout_weight="1"
android:background="#ffffff" >
</TextView>
</TableRow>
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25" />
</TableRow>
<TableRow
android:paddingTop="0.5dp"
android:paddingBottom="0.5dp"
android:background="#000000"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginBottom="20dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/bookmarks_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="left"
android:entries="#array/listitems" />
</TableRow>
</TableLayout>

How to right align text

I was trying to change the alignment of text. This is what i have:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<TableRow>
<TextView
android:id="#+id/ctime"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50"
android:text="time" />
</TableRow>
<TableRow>
<TextView
android:id="#+id/cstatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="100"
android:text="status" />
</TableRow>
</TableLayout>
</LinearLayout>
Everything is left-aligned in the output even after setting android:layout_gravity="right".
This is a part of the layout, as I cant post the entire layout.
use this one
android:gravity="right"

Design view of android text box width, height and text size

this is my code what i'm showing here:
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="28dp"
android:weightSum="80" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="20px"
android:textSize="18px"
android:text="India is best"
android:layout_weight="20" />
</TableRow>
but display is not proper
try this..dn't specify edittext height in px.always use dp for width and height.
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="28dp"
android:weightSum="80" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_weight="20"
android:text="India is best"
android:textSize="18px" />
</TableRow>
</TableLayout>
android:layout_width="" and android:layout_height="" must be fixed " fill_parent" or "wrap_content"
try this one
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25px"
android:text="India is best"
android:layout_weight="2" />
</TableRow>
</RelativeLayout>
I hope you are using Table layout what sandhya proposed.
Apart from that there are few thing which may cause problem are,
1). If you are providing weightsum then you must divide weight equally to child element,
2)if you are using child weight as horizontal then you must give then give width as 0dp and if vertical then height should b 0dp. Its give better performance.
3)avoid hardcoding values like in layout_height=28dp as your code.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/editText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="India is best"
android:textSize="18dp" >
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="India is best"
android:textSize="18dp" />
<EditText
android:id="#+id/editText3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="India is best"
android:textSize="18dp" />
<EditText
android:id="#+id/editText4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="India is best"
android:textSize="18dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
</TableLayout>
</LinearLayout>
I have edited my answer, this provide exactly what you needed

RelativeLayout with anchored top and bottom?

I'm trying to create an android screen that has a TableLayout anchored to the top, then a scrollview to fill middle, and TableLayout anchored to the bottom. I used a RelativeLayout with alignParentTop/alignParentBottom and the bottom TableLayout shows up, but the top one disappears.
Is it possible to have separate sections anchored at both top and bottom with a scrollable region filling the middle? Imagine a button bar on top and bottom with scrollable items in the middle. Here is my layout that was close but doesn't quite work. I also tried with a TableLayout and 3 rows with the middle one set to fill_parent and ScrollView, but couldn't get that to work either.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout01"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:id="#+id/CategoryTable01"
android:stretchColumns="*"
android:background="#000000"
android:layout_height="80px"
android:layout_alignParentTop="true"
android:layout_width="fill_parent">
<TableRow
android:id="#+id/tr01"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:padding="10px"
android:layout_gravity="center_vertical|center_horizontal">
<TextView android:text="TOP1" android:textColor="#0000FF" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
<TextView android:text="TOP2" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
</TableRow>
</TableLayout>
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout02"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:id="#+id/TableLayout01"
android:stretchColumns="*"
android:background="#drawable/gradient"
android:layout_height="wrap_content"
android:paddingLeft="20px"
android:layout_width="fill_parent">
<TableRow
android:id="#+id/TableRow01"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">
<TextView android:textColor="#FFFFFF"
android:textStyle="bold"
android:textSize="12dip"
android:text="Sample Line 1"></TextView>
</TableRow>
<TableRow
android:id="#+id/TableRow02"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">
<TextView android:textColor="#FFFFFF"
android:textSize="11dip"
android:text="Sample Line 2"></TextView>
</TableRow>
<TableRow
android:id="#+id/TableRow03"
android:layout_height="600px"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">
<TextView android:textColor="#FFFF00"
android:textSize="11dip"
android:text="Sample Line 3"></TextView>
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
<TableLayout
android:id="#+id/CategoryTable02"
android:stretchColumns="*"
android:background="#000000"
android:layout_height="80px"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent">
<TableRow
android:id="#+id/tr02"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:padding="10px"
android:layout_gravity="center_vertical|center_horizontal">
<TextView android:text="ONE" android:textColor="#0000FF" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
<TextView android:text="TWO" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
<TextView android:text="THREE" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
<TextView android:text="FOUR" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
</TableRow>
</TableLayout>
</RelativeLayout>
Thanks for any suggestions or help.
Michael
It is indeed possible. This is how I've got it working in one of my apps (I've cut out a bunch of irrelevant stuff like ids):
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--this is the action bar at the top of the screen)-->
<fragment
android:layout_width="match_parent"
android:layout_height="40dip" />
<!-- This is the list view in the middle -->
<ListView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dip">
</ListView>
<!-- This is a bunch of buttons at the bottom -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dip"
android:gravity="bottom">
</RelativeLayout>
</LinearLayout>
The key is to set your middle listview to height 0dip and let layout_weight take over - layout_weight is kind of comparable to percentage widths/heights in HTML - if you have 4 different elements with weight 0.25, they'll each take up a quarter of the screen. So weight 1.0 takes up whatever it can.

Categories

Resources