I need to do an activity with two "parts". The first one, uses the top half of the screen, and there, I will show some fields (name, date,...). The second one, uses the bottom half of the same screen, and there, I will show a table, with three columns, and with some rows. The quantity of rows is undefined, because they come from a web service.
My doubt is how to do this second part, with a vertical scrollbar table, where the user will see the first half static, and could be able to roler the bottom half to see all rows of the table (like an iframe). I need to use table, because my cells need to be aligned.
I have already tried tablelayout, listview, gridview, and I can't find a way to show the vertical scrollbar.
You could use a ScrollView.
Note though that ScrollView supports one direct child so you may wrap everything up.
You can use something like the following:
MainLayout
TopHalfElements
ScrollView
Linear/relative/frame/whatever layout
Rows From Webservice etc.
You need to have a main layout inside the ScrollView as it only supports one direct child.
Related
I am trying to put multiple lists that don't need to be scrollable inside a ScrollView. In other words, I have a TextView as a header for a category, with a list under it. Then another TextView as another header, with another list under that. And so on. This is in a vertical LinearLayout.
I want to be able to scroll through this layout as it gets off the screen when it has too much info, but I want all the contents of the lists to be displayed.
I've tried putting the headers (the TextViews) and the lists inside a vertical LinearLayout, and that LinearLayout inside a ScrollView. The problem with that approach is - all the lists have a max vertical dimension of exactly one element (if I set them to "wrap content"), despite the lists having multiple elements. Believe it or not, the lists do scroll (and they're inside of a ScrollView, more exactly, inside of a ScrollView -> LinearLayout).
If I remove the ScrollView, then the lists do indeed appear with all their elements, but I can't scroll the view if it goes off the screen.
So, if I use a ScrollView, I only get one element per each list. If I don't use it, I get all the elements of the lists correctly, but it doesn't scroll.
Any ideas of solving this? Thanks!
Nevermind, eventually found the answer here and it works perfectly:
https://stackoverflow.com/a/27818748/5627584
This ^^^ is a very underrated answer as I have hardly found it, but it's very, very useful when trying to include lists inside of superior layout node that has to be scrollable (inside of a ScrollView -> LinearLayout that contains other interface elements).
Right now I'm stuck how to manage to build a specific Activity in my app. I've added an image so I can explain my problem:
So first of all: all the content will be loaded from an API. "Static text" in my image means that I can define these parts in my activity.xml and don't have to do that in my Activity.java because these parts will be always the same for the screen (meaning the size of the elements, the content will be loaded from my API).
The green box should be horizontal scrollable or not depending how many boxes have to be shown here (1 to 3 possible).
The blue box will be generated in my Activity (in the end it should look like a table) and I want to define the layout of a single row in a separate xml (e.g. table_row.xml) so I could change it easily. This table can have up to 100 rows depending on how many are returned by the API.
So my problem right now is: Obviously this whole layout has to be scrollable so my first idea was to use ScrollView and a LinearLayout as child. But I read here on stackoverflow that the performance will be really poor if you use LinearLayout and add Views to it. So everyone recommended using a ListView for this part (meaning the blue box for my Activity). But that would mean only my blue box will be scrollable as you should not use a ListView in a ScrollView.
So my question is: How can I make this whole screen scrollable with a table dynamic in size without losing performance?
Put the first three layouts as ListView Header and make your blue box layout as the list view. By this you'll be able to scroll the complete View i.e. Blue Box, however the first three layouts will be static and won't scroll.
I've got a listview and I want there to be two textviews and two buttons underneath it (3 of which may be hidden in the code). Every single layout I tried either results in the four elements being anchored to the bottom of the screen even when the listview is only a few lines, or getting pushed off altogether if the listview gets big enough. Any ideas?
It sounds like you've used android:layout_below="#id/listVieId" and android:layout_alignParentBottom="true" as these would give the results you mentioned. It sounds like what you want is addFooterView(View v)
Note what the Docs say
NOTE: Call this before calling setAdapter. This is so ListView can wrap the supplied cursor with one that will also account for header and footer views.
I need to create large table with horizontal and vertical scrolling. Each cell of this table should be clickable.
To make it clear this is a picture of what I am trying to achieve. Scrollable area on the center, empty cells and cells with numbers should be clickable.
I've tried different approaches, but all end up failed:
GridView:
Problem: gridview elements are clickable and scrollable, but scroll is only vertical.
HorizontalScrollView is placed in VerticalScrollView, while LinearLayout, which represents a table row, is placed in HorizontalScrollView. And program built table adds new Linearlayouts row by row. Scrolling is implemented manually in a parent layout by setting coordinates to scroll views in TouchEvent. I'm using custom ScrollViews which return false in ontouchevent to set coordinates in parent. Scrolling works fine, but when we attach onClickEvent to a cell(textview), it breaks. Clicking works, but scrolling doesn't. I've tried different modifications (onintercepttouchevent) of this approach, but best result was scroll causing click after scrolling.
Also table header should be fixed vertically.
The first and last column should be fixed horizontally.
I wonder how Google made this in Google Docs app. Their table is perfectly scrollable and clickable.
I found working solutuion. Instead of OnTouchEvent I use onScrollChanged and onHorizontalScrollChanged for manual scroll. With this approach clicking works fine but doesn't work diagonal scroll, because event parameter x is always 0 in onScrollChanged(and opposite in onHorizontalScrollChanged).
I want to create a screen that has a column of scrollable images on the left and a similar column on the right with space in between them. The user selects an image in the left column and based on that selection, the images in the right column get filled up. I can drag images from the right column into the space in between to create a composite image.
What kind of layout should I use to accomplish this? Is this one view or three views? Is this a Vertical Linear Layout with three columns and do I need to use Grid view in the left and right columns?
Thanks!
IMHO, the left-hand list of views is a ListView. The right-hand list of views is a ListView. The middle...I have no idea, since I do not know what you mean by "create a composite image". It might be a ListView, it might be a vertical LinearLayout, it might be something else.
The three columns (ListView, thingy, ListView) are probably formed via a horizontal LinearLayout or a RelativeLayout.