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">
. . .
Related
strong text
Hi All,
I need to get some help to implement implement a Vertical scroll view with Multiple Horizontal rows inside of it, this is what I have so far, any help or hint would be highly appreciated
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TableLayout android:id="#+id/threeByThreeTable"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0,1,2"
android:padding="10dp"
>
<TableRow android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/mygallery1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
/>
</HorizontalScrollView>
</TableRow>
<TableRow android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/mygallery2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
/>
</HorizontalScrollView>
</TableRow>
<TableRow android:id="#+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/mygallery3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
/>
</HorizontalScrollView>
</TableRow>
</TableLayout>
</ScrollView>
Put your TableLayout inside a ScrollView instead of a LinearLayout. Just keep in mind that a ScrollView can only have one child.
Why not just use a ListView and remove the lines between the items? Seems like that would work much better than rolling your own view
Put a Vertical Linear Layout inside your ScrollView
Inside the vertical linear layout, create your HorizontalScrollViews.
It should work probably, please let me know if you have questions.
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've got a vertical LinearLayout (green rectangle), and I'm trying to programatically inflate and insert multiple TableLayouts (red rectangle) to this LinearLayout. Each tablelayout contains 4 cells in a 2x2 arrangement.
It works except that any layout_marginBottom I set for the TableLayout has no effect, the red rectangles are always tightly packed inside the LinearLayout. I would like to create some vertical spacing in between each table.
Please suggest what is wrong with my XML:
LinearLayout:
<ScrollView 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/levellist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
TableLayout (inserted dynamically). Note the layout_marginBottom that has no effect :
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="100dp"
android:stretchColumns="*" >
<TableRow
android:id="#+id/TableRow01"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<include
android:id="#+id/levelview0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
layout="#layout/levelmenu_level" />
<include
android:id="#+id/levelview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
layout="#layout/levelmenu_level" />
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<include
android:id="#+id/levelview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
layout="#layout/levelmenu_level" />
<include
android:id="#+id/levelview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
layout="#layout/levelmenu_level" />
</TableRow>
</TableLayout>
You have a bunch of Views in this TableLayout that are the same. I would suggest trying to use a GridLayout. It should help with so memory management and recycling. But to answer your question, it looks like your are setting the margin for the entire table, not each row. Have you tried putting your layout_margin inside of your row tag? You can also try setting the Padding instead? That way you put the spacing inside of the rows. However, I believe you should get the same effect either way. Margin is outside of the view, padding is inside.
http://developer.android.com/reference/android/view/View.html#attr_android:paddingBottom
<TableRow
android:id="#+id/TableRow01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="???dip">
<include
android:id="#+id/levelview0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
layout="#layout/levelmenu_level" />
Please take a look at this XML code:
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:isScrollContainer="true"
android:scrollbarStyle="outsideInset">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageButton
<!-- Some Code -->
/>
<ImageButton
<!-- Some Code -->
/>
<ImageButton
<!-- Some Code -->
/>
</TableRow>
</TableLayout>
The three ImageButtons are displayed fine in my device (Centralized exactly). However, when I test the app in another device with larger screen, the three images seems to be aligned to the left.
Is there a way to make the layout centralized? No matter what the screen width is?
this should do it.. if i have understood your problem in right manner...
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:isScrollContainer="true"
android:scrollbarStyle="outsideInset"
android:gravity="center_Horizontal|Center_Vertical">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_Horizontal|Center_Vertical"
>
wrap with linearlayout every image button in similar format . set gravity for each linearlayout to be center. and layout width = fill_parent for all linearlayouts.
Simple problem:
With the XML layout shown below, I have some views wrapped in a GestureOverlayView. As shown below, my first row is blended with the second row, as-if the first row is transposed right on top of the second.
Now when I take the GestureOverlayView out of the code and leave everything else as-is, my table looks fine - the rows are separate and not on top of each other.
I'm wondering why the rows overlap like that with the gestureOverlayView present?
Screenshot showing the problem: http://img413.imageshack.us/img413/4994/overlayblending.png
Thank you
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<android.gesture.GestureOverlayView
android:id="#+id/gesturePage01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0">
<TableRow android:id="#+id/TableRow01" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView
android:text="Connection info"
android:id="#+id/tvCon1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#F0F0F0"
android:textColor="#FF0000"
/>
</TableRow>
<TableRow android:id="#+id/TableRow02" android:layout_width="fill_parent" android:layout_height="wrap_content">
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/tvMessages"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=""
/>
</ScrollView>
</TableRow>
</android.gesture.GestureOverlayView>
</LinearLayout>
I went ahead and put my tableRow into a TableLayout and that fixed the problem.