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.
Related
I have use two Scroll view in One activity.Each scroll view inner add table layout.Each table layout add records in programmatically from my database value.I need add 10 records in each table at a time scroll view height in wrap content and more than 50 records add to table scroll view maximum height set in 500.How I do this?Please help me. Follow my XML code
main_activity.xml
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="fill_parent"
android:layout_height="450dp"
android:layout_alignParentRight="true">
<TableLayout
android:id="#+id/main_table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0,1"
android:layout_column="0"
android:layout_weight="1.0"
android:layout_below="#+id/relativeLayout"
android:layout_alignParentLeft="true"
xmlns:android="http://schemas.android.com/apk/res/android" />
</ScrollView>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/req_head"
android:layout_below="#+id/scrollView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"></TableLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView4"
android:layout_below="#+id/req_head"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="0dp">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/maintable2">
</TableLayout>
</ScrollView>
if i follow your question, I think you need to fix the scroll views height. And scroll view can be more than one..In that case put your ScrollView into a
LinearLayout make the height of scroll view wrap_content and fix the size of parent LinearLayuot according to your need. like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="450dp"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout
android:id="#+id/main_table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0,1"
android:layout_column="0"
android:layout_weight="1.0"
android:layout_alignParentLeft="true" />
</ScrollView>
</LinearLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/req_head"
android:layout_marginTop="10dp"></TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView4">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/maintable2">
</TableLayout>
</ScrollView>
</LinearLayout>
</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.
i am trying to achieve the following in one of my layouts for my android app:
I would like to have a layout that holds the main content (linearlayout with other content) and a footer (linear layout with other content). The main content should be centered both horizontally and vertically. The footer should just be centered horizontally and always stay at the bottom.
In addition to that, the main content and the footer should be wrapped in a scrollview because it is possible that the main content grows and all the content should stil be accessible.
How can I do that?
I think the following gets close to what you want with the assumption that when you wrote 'The footer should just be centered horizontally and always stay at the bottom.' you meant the bottom of the screen.
<?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"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_above="#+id/footer" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:minLines="0"
android:visibility="invisible"/>
<TextView
android:id="#+id/body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My main body text to display"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:minLines="0"
android:visibility="invisible"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="#+id/footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My footer text to display"/>
</LinearLayout>
Assuming this isn't quite right it should hopefully at least give you some ideas.
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.)
I have a vertical scrollable layout with lots of items, working fine.
I am trying to place a new linearlayout to the bottom of the screen that would NOT be part of the scrollable layout.
That is, it would sit on the buttom (like an adview) independent of the scrollable part.
I was only able to place it inside the scrollView. How can I place it below, so it would always visible ?
Use a RelativeLayout, and organize it 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="fill_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_above="#+id/linearLayoutThatDoesNotScroll" >
<LinearLayout
android:id="#+id/linearLayoutWithLotofContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/linearLayoutThatDoesNotScroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
</LinearLayout>
</RelativeLayout>
The trick is in the ScrollView placement, at the same time it is aligned with the top of the screen AND above the lower, fixed, LinearLayout. It just works.
something like this :)
<?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" >
<ScrollView android:id="#+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</ScrollView>
<LinearLayout android:id="#+id/bottom"
android:layout_width="fill_parent"
android:layout_height="10dip" />
</LinearLayout>
You will add your bottom content to the bottom linearLayout with the android:id=bottom :)
If you used a vertical LinearLayout to hold the scrollable layout, then you could add the adview to the LinearLayout below the scrollable layout and it would appear at the bottom of the screen. (assuming your weights are set correctly,and the scroll layout is set to WRAP_CONTENT)
A RelativeLayout would allow you to set the adview to align itself with the bottom of the scrollable layout as well, but you would still need to make sure the scrollable layout was set to WRAP_CONTENT so it didn't automatically take up the entire screen.
<?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" >
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="100px"
android:layout_height="wrap_content"
android:text=" Ok "
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:background="#drawable/button_style"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:id="#+id/scrView"
android:layout_above="#id/dialogButtonOK"
android:layout_alignParentTop="true"
>
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:id="#+id/main_table" >
</TableLayout>
</HorizontalScrollView>
</ScrollView>
</RelativeLayout>
This is worked for me