I'm trying use TableLayout to make a table and is much informations to screen of smartphone, so i need of a Horizontal Scroll, but if i use HorizontalScrollView, the TableLayout and my button of the screen have the background blank, the background simply disappears. I try use ScrollView (vertical) in test and all work fine, so the problem is in HorizontalScrollView in my opinion.
I try to change the width to a number, for example, width:"450 dp" and all resolved, but to approximately "1400 dp" all returned... My table is very large, have approximately 21 columns, so they tableLayout is much higher of "1400 dp".
i'm losing the hope, trying anything and nothing resolved.
somebody help me.
image below:
TableLayout with all working, but with ScrollView vertical, cutting the table without horizontal scroll:
http://s11.postimg.org/k9hg1a79v/Screenshot_2015_02_19_15_43_56.png
TableLayout with HorizontalScrollView, all backgrounds missing, this is the problem, TableLayout, TableRow and button lost the background.
http://s4.postimg.org/iprnwxg65/2015_02_19_15_41_14.png
XML Code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/HorizontalScrollView1"
android:layout_width="match_parent"
android:background="#drawable/background_start_screen"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="#+id/table"
android:background="#drawable/border"
android:layout_marginTop="5dp"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</TableLayout>
<Button
android:id="#+id/button1"
android:background="#drawable/button_deny_state"
android:layout_marginTop="20dp"
android:textColor="#FFFFFF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="fechaTela"
android:text="Fechar" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
You have to inflate items to HorizontalScrollView one by one with using adapter. Firstly you have to learn adapter mecanism.
This is an adapter example for custom listView :
http://www.learn2crack.com/2013/10/android-custom-listview-images-text-example.html
This can helps to solve your problem :
https://code.google.com/p/androidbeginner/source/browse/trunk/andriod/src/slieer/com/layout/TableAdapter.java?r=48
Related
I have a layout in a scrollview and I add another layout to the end of the first one. Actually I am trying to make a one page design and the rest of the other views will appear after scrolling. I tried to put linearlayout1 and linearlayout2 to another view but it didn't work. Also I set scrollview android:fillViewport="true" but it made the scrollview in screen size.
I've added an image of what I want, but it could also be one view, I mean lin1 and lin2 together.
I can set width and height for one phone but I want to do this for each screen. For example like yahoo weather app. They have done one layout for first view and start another view from the end of screen. I tried so many things but I couldn't imagine how to put layouts. Could you help me?
Thanks for your help
Here is what I want
Here is I tried:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linearlayout1"
android:background="#android:color/holo_purple"
android:layout_width="match_parent"
android:layout_height="350dp" >
<TextView
android:text="LinearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearlayout2"
android:background="#android:color/holo_blue_bright"
android:layout_width="match_parent"
android:layout_height="250dp"
android:orientation="vertical">
<TextView
android:text="LinearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:background="#android:color/holo_green_light"
android:layout_width="match_parent"
android:layout_height="350dp">
<TextView
android:text="LnearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
But unfortunately I couldn't configure this for each screen size.
enter image description here
Just try this.
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/action_bar"
Instead of hardcoding the height as in:
android:layout_height="250dp"
Set android:layout_height="0dp" and use
android:layout_weight="25"
And also in the other layout use weight. Weight works like this, if you have 3 components in your container, set the weights to let's say 1, 2 and 3 => they will take in that order 1/6, 2/6 and 3/6 of the container. 6 being the sum of 1,2,3. So here instead of using heights as 350 and 250, you can set them to 0 and use weights 2.5 and 3.5 or 25 and 35.
i am developing an android app where i am showing day wise channel schedule (multiple rows).
now in this i have to provide both vertical and horizontal scrollability.
vertical scrollability will be normal , but horizontal scrollability should be synchronized
that is when user scrolls horizontally all other rows should also be scrolled in a sync.
i tried using table layout but its not going good with my requirement and i have also tried TwoWayView but i am not able to sync the horizontal scrolling.
i would like to know i anyone have faced/solved the similar situation.
Any leads on this is highly appreciated.
xml for vertical and horizontal Scrolling :-
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/vertical_scroll_view2">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/horizontal_scroll_view2">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="910dp"
android:id="#+id/scheduleContainer"
android:orientation="vertical"
/>
</HorizontalScrollView>
</ScrollView>
.....
xml for TwoWayView:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/weekday"
android:layout_height="fill_parent"
android:layout_width="40dp"
android:textSize="12dp"
android:textStyle="bold" />
<com.mobiotics.tvb_stb.utilityclasses.TwoWayView
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/hlist"
style="#style/TwoWayView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toRightOf="#id/weekday"
android:scrollbars="none"
android:drawSelectorOnTop="false"
tools:context="com.mobiotics.tvb_stb.activity.HomeScreenActivity" />
</RelativeLayout>
i am adding twoway list to linear layout .
If you can have a ListView, I would start there. Just drop the ListView into a HorizontalScrollView. Make sure to set the width of the HorizontalScrollView to wrap_content. I noticed you have it set to fill_parent.
I'm having trouble getting a GridLayout to scroll horizontally.
I found a similar question Gridlayout + ScrollView. I tried that method, but it didn't work.
It cuts out many tables (because it was supposed to go display all tables from 1 to 20).
Here is the xml file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="16dp" >
<android.support.v7.widget.GridLayout
android:id="#+id/table_mapGrid"
android:layout_width="250dp"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
<include layout="#layout/cell_list_loading" />
<TextView
android:id="#+id/table_errorView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:text="#string/message_error_connection"
android:visibility="invisible" />
</FrameLayout>
I want to have dynamic content displayed, varying the number of columns and rows possibly with empty spaces between tables.
This I have accomplished, but the problem is when the width of the GridLayout becomes greater than its container's, I wanted to solve that using horizontal scroll, but it doesn't seem to work...
Any suggestion?
Well I found the solution
It seems like the android ScrollView works as a VerticalScrollView and only that (the name is not so intuitive as HorizontalScrollView).
So to make something scrollable vertically and horizontally, you need to nest a (Vertical)ScrollView inside a HorizontalScrollView, or the other way around, like this
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent">
<!-- Your content here -->
</HorizontalScrollView>
</ScrollView>
The nested HorizontalScrollView / ScrollView will not allow you to scroll both directions at the same time.
I had this problem and created a custom component for that, here is the link if it can help anybody :
https://gist.github.com/androidseb/9902093
I tried looking at numerious examples and posts but none of them matches my problem.
I need to make a very long (horizontal) table with many columns so it is impossible to display in a single screen. And I don't want to spilt the table because it is important that I display my table in this way.
I have pasted my XML layout below (including the main important ones)
The thing is if I remove the code:
android:fillViewport="true"
from the HorizontalScrollView then my table inside it, gets squeezed in one place, especially at the left side of it. It doesn't even use much of this HorizontalScrollView container area.
And,
If I use this code, then this HorizontalScrollView shows my whole table inside it - the columns are squeeze to make sure they fit in this scrollview.
I just want this scrollview to display only the content of my tablelayout that fits in the screen width, so I can scroll the remaining columns. But right now, I don't seem to get anywhere near.
So how do I solve my problem? Am I doing something wrong ?
Also here is my XML layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<HorizontalScrollView
android:id="#+id/horizontalScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal"
android:fillViewport="true">
<TableLayout
android:id="#+id/bot_scoreBoard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/table_shape"
android:orientation="horizontal"
android:stretchColumns="*" >
<TableRow
android:layout_height="fill_parent"
android:layout_margin="2dp"
android:background="#ffffff"
>
<TextView
/>
....
more than 16 columns of made using TextView
....
</TableRow>
</TableLayout>
</HorizontalScrollView>
</LinearLayout>
I got the answer. It was because I was using the
android:stretchColumns="*"
in the TableLayout.
Plus my TextView which were the columns, needed to some specific width size rather than just
android:layout_width="fill_parent" or "wrap_content"
Those were the problems.
You should wrap your TableLayout with a LinearLayout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<HorizontalScrollView
android:id="#+id/horizontalScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TableLayout
android:id="#+id/bot_scoreBoard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/table_shape"
android:orientation="horizontal"
android:stretchColumns="*" >
<TableRow
android:layout_height="fill_parent"
android:layout_margin="2dp"
android:background="#ffffff" >
<TextView />
....
more than 16 columns of made using TextView
....
</TableRow>
</TableLayout>
</LinearLayout>
</HorizontalScrollView>
You are using android:stretchColumns="*" you have to use some definite value with your layout_width instead of match_parent and wrap_content.
for ex. layout_width = "250dp"
I have a table to which I have added a vertical & horizontal scrollbars. The horizontal scrollbars appears on the bottom on the last row of the table. Due to this the border of the table isn't visible. I want it to appear below the last row of the table. I tried adding margins, but nothing worked. Same is with vertical scrolling too. This is my xml :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:scrollbars="horizontal|vertical" android:layout_weight="1">
<HorizontalScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:layout_marginBottom="10dp" >
<TableLayout android:id="#+id/browseTable" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_marginBottom="20dp"
android:background="#FF0000" android:stretchColumns="1,2,3">
</TableLayout>
</HorizontalScrollView>
</ScrollView>
And this is the result :
Any helpline is highly appreciative.
Now i understood what you are looking for. I tried and got solution by using image view inside Scroll and Horizontal Scroll views, its working fine. It may or may not work with your Table Layout, test it.
Add below line in your Table Layout in XML file.
android:padding="5dip"
Let me know is it working or not.