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.
Related
I am building an app where I want a message to be displayed at the bottom and top of the List like this example. Ive tried to nest the ListView inside a column, but that is giving me an error. Please Help
Use a column with 3 children. Put an expanded in the middle one and put your ListView in that.
The expanded will take up any room that is not not taken up by the top and bottom children of the column, ensuring that your ListView adapts to whatever you put around it but it always takes up every pixel that you didn't already need for the top and bottom children.
What I'd like to do is create a grid layout that has multiple live components. I'm trying to implement this layout, and am struggling to figure out the best way of doing it.
The 4 main elements of the grid layout:
Imageview (the green bar). It changes colours to green/ red/ or yellow, depending on the delay.
Textview (the title). The title changes based on an update call. It's the recommended title.
Textview (Delay). Will be a string with the delay status (either No delay or 30 Minutes)
Imageview (background for delay text). Will never change.
After reading about this on StackOverflow, an embedded grid layout seems to be the best choice, but I haven't seen a good way of incorporating different elements (that are set every new "Update"/ pageload) into a Grid Layout without having multiple views set for each element.
Here is the picture I want to implement (http://imgur.com/8TrFvl8)
Perhaps consider using a recycler view instead
I'm building a layout within Eclipse for Android using the RelativeLayout. I lay down a simple stack of buttons one on top of each other. For some reason the button snaps to the first button position even though I clearly place it down on the last stack of buttons. I try everything to move it to the right position eventually I just let the layout builder stick it to the bottom of the screen edge.
When I try this view inside the app, the last button is magically snapped to some random spot usually near the top. Obviously incorrect. As a hunch I tried it again but I left it alone this time, when I laid the last button down again ( which within Eclipse Layout builder its snapped to the first elements position for some crazy reason). Surprisingly within the app itself it appears in the proper location. So this must be a bug with the Layout builder itself.
It looks horrible in Layout builder (almost unusable) and the position of UI elements totally wrong, is this some known bug with Layout Builder + Android or do I need some update or new SDK or something?
There are many reported complaints about the ADK Editor for Eclipse, but one alternative is to try DroidDraw
http://www.droiddraw.org/
The preference of some Android developers is to directly modify the XML. This often provides more flexibility as you can see the exact rules that are defined for your UI.
If you are looking at just stacking Buttons on top of each other, you may want to consider a LinearLayout.
http://developer.android.com/reference/android/widget/LinearLayout.html
This is a layout that arranges its children in a single column or a single row.
Relative layout every "view" is positioned relative to something else. It would help you to understand better if you look at the xml. You will see what each item is aligned on. It is difficult to get this layout right as you see especially when you design in eclipse and run on an avd or real device. Consider placing a linear layout inside the relative layout and your buttons in that. This way your button group is together in a row or column and next to this you could have text or something.hard to explain but group like things together and nest layout inside other layouts.frame layout only one item is viewable at a time,like pages in a book or slide images. I hope I explained this good. I have no idea why you would do buttons that way.absolute layout is x,y positions where you put it is where it stays. Like that's gonna work. Try a different screen density and things are bunched up in the corner.like I said the key is nesting the layouts
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.
I am learning Android by implementing a clone of Mastermind. I want to break up the screen (or View) into three parts: the board with the users guesses so far and feedback, a series of control buttons, and a series of buttons to pick the color of the next peg.
My instinct is to do this is a modular way. The layout files uses nested LinearLayouts (I know not the most efficient thing to do, but this is an educational experience.)
The "board" is a custom View where I do a lot of drawing with a Canvas. The buttons on the bottom are declared in the layout file. Notice the orange strip to the right?
Right now that is another custom View. I want to add a variable number of buttons to that custom View based on the number of colors the player can choose from. A button press would select the color for the next peg in the player's guess. (There are 3 versions of the game, easy, medium, and hard each with a different number of colors.)
So, how do I add a variable number of buttons to the custom View I am creating? Or am I approaching this in the wrong way? Should I use a prebuilt layout? If so, which one and how could I dynamically change the number of buttons in the layout?
Thanks for any help. Cheers!
You can do this in two ways:
Using a predefined layout and setting initially the property
"visibility" of all the buttons to "gone", then programatically you
can set the "visibility" of the buttons you need to "visible". The
"gone" property makes the button invisible and also not consumes
space in the layout.
Adding dinamically buttons to the main layout, first you will have to
create or "inflate" them.
The second options is more powerful, but also more difficult if you are learning.