TableLayout appearing on top of another TableLayout - android

I have the following definition:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/leftContainer"
android:layout_weight="0.8">
<TableLayout
android:id="#+id/drinksTable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="*"
android:stretchColumns="*"
android:padding="0dp" />
<TableLayout
android:id="#+id/itemsTable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="*"
android:stretchColumns="*"
android:padding="0dp"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Both table layouts are built programatically.
I want the second table to appear directly beneath the first table, however the best I can do is get it to sit at the bottom of the layout which I don't like (using alignParentBottom).
How can I have the itemsTable appear directly beneath the drinksTable?

Just convert your layout to a LinearLayout, making sure to add android:orientation="vertical"; this will make each element stack vertically.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/leftContainer"
android:layout_weight="0.8"
android:orientation="vertical">
<TableLayout
android:id="#+id/drinksTable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="*"
android:stretchColumns="*"
android:padding="0dp" />
<TableLayout
android:id="#+id/itemsTable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="*"
android:stretchColumns="*"
android:padding="0dp"
android:layout_alignParentBottom="true" />
</LinearLayout>
Note, however, that if the number of elements is too great, they will flow off the screen at the bottom. (You may want to wrap this LinearLayout in a ScrollView.)

Related

Table layout continue expanding under other elements fixed at the bottom

I have a table layout inside a relativelayout. the relativelayout contains the table at top, and another linearlayout at the bottom. When i add more rows to the table it gets bigger till it takes all the screen size, then the scroll view that contains the table rows starts working!
here is the layout code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableLayout
android:id="#+id/TableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/WHITE" >
<TableLayout
android:id="#+id/TableLayout2_general_horizantalscrol"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TableLayout>
<ScrollView
android:id="#+id/scrollView_report_rows"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/WHITE"
android:overScrollMode="never"
android:scrollbarStyle="outsideInset" >
<TableLayout
android:id="#+id/tablelayout_general_scrollview_row"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TableLayout>
</ScrollView>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<TableLayout
android:id="#+id/tableLayout_general_Itemname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center" >
</TableLayout>
<TableLayout
android:id="#+id/tableLayout_general_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center" >
</TableLayout>
<TableLayout
android:id="#+id/TableLayout_general_total"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center" >
</TableLayout>
<TableLayout
android:id="#+id/tableLayout_general_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center" >
</TableLayout>
</LinearLayout>
</RelativeLayout>
I want the scrollview inside the first tablelayout to start working when reaching the linear layout. Or in other words, I want the first tablelayoud not to take the full screen space to expand in, and leave some for the linear layout. I want my app to run in portrait and landscape orientations, and on several screen sizes, so I don't like to hard-code height values.
Any help please?
Try adding android:layout_above to your table layout.
<TableLayout
android:id="#+id/TableLayout1"
android:layout_above="#+id/id_of_bottom_linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/WHITE" >
Don't forget to assign the same id to the bottom aligned linear layout.
As an aside, your layout seems to use too many table layouts which can affect performance.

Space between views in LinearLayout

I have a linear layout inside a scroll view, this linear layout contains many table layouts that are inserted dynamically during the application life. When I have more than 1 table layout they are too close to one another:
Here is the code for the table layouts:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/TableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="vertical"
android:background="#color/eggshell" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/messageBoardTitleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/fill"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/messageBoardMessageTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/fill" />
</TableRow>
and this is the code of the scroll view and the linear layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp" >
<ScrollView
android:id="#+id/messgaeBoardScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/messageBoardLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp" >
</LinearLayout>
</ScrollView>
How can I create some kind of a break between the two table layouts?
why don't you go for the android:layout_margin parameter in android... It will allow you to put some space between any two layout or between layout and screen border..
Check out this Android Developer Link..
Hope it will help you..!!!
Add android:layout_margin instead of padding
Padding adds space inside the layout, not between other layout
Remove your padding from your TableLayout which is android:padding="10dp" besides that try out with the margin android:margin="10dp".
As padding adds space in outer part of the view and margin leaves a space in inner part of your view.
Add
android:margin_top=10dp;
instead of layout_padding.

Android textview troubles in one page

Hy everyone,
i have got a lot of text to diplay in one page, but i saw only first textview, other disapiard. Where is other textrview?
Code, i dont know why i see only first texttt and a lot offf blank page. And that isall:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="texttttttttt"
android:id="#+id/textView" style="#style/MetricPrefixTitle"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="texttttttttt"
android:id="#+id/textView1" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Valute"
android:id="#+id/textView" style="#style/MetricPrefixHeader"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="textttttttttttttt"
android:id="#+id/textView1" android:layout_gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="text"
android:id="#+id/textView" style="#style/MetricPrefixHeader"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="textttttttttttttttttt"
android:id="#+id/textView1" android:layout_gravity="center"/>
</LinearLayout>
</ScrollView>
You didn't set android:orientation attr in LinearLayout, the default one is horizontally so your textViews are positioned next to each other, if you scroll your text view from left to right you will see the other ones. What you want is to set android:orientation to vertical.
Besides the orientation, your layout_height-"match_parent" will cause your view to expand to the size the parent allows. You should use layout_height="wrap_content" when you want the view height to be the height of the contents.

Why my scrollHorizontally doesn't work?

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
tools:context=".MainActivity" >
<TextView
android:id="#+id/instruction_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollHorizontally="true"
android:text="#string/Texto_de_abertura"
android:textColor="#00FF00" />
<TableRow>code<TableRow>
</TableLayout>
This is the code I'm using. The string Texto_de_abertura is really big, and it keeps using a lot of lines to put the entire string on the screen, not only one with scroll horizontally on as I wanted.
To scroll horizontally you can place the TextView inside a HorizontalScrollView:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
tools:context=".MainActivity" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/instruction_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollHorizontally="true"
android:text="#string/Texto_de_abertura"
android:textColor="#00FF00" />
</HorizontalScrollView>
<TableRow></TableRow>
</TableLayout>
The Android documentation describes scrollHorizontally as "Whether the text is allowed to be wider than the view (and therefore can be scrolled horizontally)" meaning a HorizontalScrollView is required to make the view scroll alongside setting the property to allow it to scroll. https://developer.android.com/reference/android/widget/TextView.html#attr_android:scrollHorizontally

How to make a scrollable TableLayout?

Look at the XML code here please:
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Some stuff goes here -->
/>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Some stuff goes here -->
/>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Some stuff goes here -->
/>
</TableRow>
</TableLayout>
My code is much longer than that but I just eliminated the unnecessary parts.
The problem is I want to make this TableLayout a scrollable so that all of my stuff can be shown.
I tried to put this line in the TableLayout in order to make it scrollable:
android:isScrollContainer="true"
But it does NOT do the job. Is there a way ?
Encase the whole thing in:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:layout_weight="1">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
...
</ScrollView>
You don't technically need the LinearLayout in the ScrollView:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:layout_weight="1">
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:isScrollContainer="true">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<--!Everything Else You Already Have-->
</TableRow>
</TableLayout>
</ScrollView>
Once you take up enough room within the ScrollView, the scrolling effect will activate (kind of like an HTML TextArea, once you have enough lines of text, the scrolling activates.)
You can also nest the ScrollView, but again you cannot feel the scrolling effect until you have enough content in the ScrollView.
thanks mbauer it's solved my problem
i place in order
TableLayout
TableRow with end (for the header of columns)
ScrollView
LinearLayout
x TableRow with end
end LinearLayout
end ScrollView
end TableLayout
It works too inside Constraint Layout. Just add the following attributes on your TabLayout.
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:id="#+id/tableLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="true">
. . .

Categories

Resources