I want to make a picture gallery with a vertical layout with two parts: image on
top, and horizontally scrollable icons below. I know how to do this.
But I also want that, when autorotated, icons stay on the right. That is, I want
to change the vertical layout by a horizontal one, and horizontal
scrollbar by a vertical one.
How to do this? Any clues/links would be appreciated.
Thanks!
L.
You'll want different layouts for each orientation (landscape, portait) and possibly more for different screen sizes. Start with the android documentation.
If you have specific issues, post the issue(s), some code for what you have tried and we'll see if we can help you.
you must have multiple layouts. create 2 layouts. one in layout folder for portrait and copy it and paste it in layout-land folder for landscape then customize each other.
Related
I am wondering how I would design a calculator with graphics similar to the following: Design help for Calculator App or https://play.google.com/store/apps/details?id=jp.Appsys.PanecalST.
The key requirements:
The buttons must be squared (it can pop out etc. but squares are more aesthetically pleasing than rectangles).
It must be device compatible and retain square buttons upon orientation change
My problem is that Relative formatting (as I attempted) disorients the layout in different devices and is not as nice as I hoped. (i.e. trying to design the button to harbor no empty space in one device using relative instructions. One idea I fancy is putting a center button and orienting the others above left etc. so at the very least, no empty space is in the center.
Below is the designs I made:
I prefer the first image but I neglected 0 (only buttons for 1-9). How would attempt at transforming these designs to code?
*I think I may use ImageButtons. I will include images based on density but how would I account for different screen sizes?
First of all, for your calculator, use LinearLayout.
Link: Documentation will be found here
Secondly, To Support multiple screen,
This documentation will help, documentation1, documentation2
What would I do in this situation?
First of all, I would use the LinearLayout as my primary layout and give it an orientation > Vertical instead of RelativeLayout. This LinearLayout is for the whole screen (The output, the numbers and other functions). Then for each line, say for the output screen, I would put it in another LinearLayout (Orientation Horizontal) inside the previous LinearLayout (NestedLayout). For numbers in each row, I would use a new LinearLayout.
For the second problem of yours, I would use buttons instead of images as images take large space in perspective of buttons which will unnecessary increase the app size. To support my button for multiple screen, I would use Weight option in android for buttons. This stackoverflow answer has a nice description.
I hope it helps.
Cheers mate!
I am using Linear layout with horizontal orientation to put images beside each other. However, is there way that the images can automatically go to the next line incase they dont fit due to screen size?
I just dont want small screen (or small densities) to truncate my images
Thank you
Use RelativeLayout and reorder images via code according to image sizes and space.
OR
Extend GridLayout and make your own implementation of it.
This is not possible in LinearLayout as it is.
I have been struggling to figure out which layout to use and how to achieve what I am looking for. I've tried gridlayouts, linear and relative layouts as well as scroll views in many different combinations. What I want is something like Google now.
I have two buttons to launch the two modes in my app. I have an imagebutton in the top right which they press for more information and when they do so a text view slides out. I have made the layout work, and to overlay the imagebutton on my mode buttons I require a relative layout. However my problem comes from trying to optimise for different screen sizes. I would like it to centre the buttons to rest a quarter of the way down and the layout to pop out underneath towards the half way mark. For the bottom button I want it three quarters of the way down with a text view that drops down towards the bottom. If there isn't sufficient space to fit everything I want a scroll view for when the text views appear, but otherwise it should fit comfortably and not require scrolling.
How do I do this? Two nested relative layouts within a linearlayout, both with equal weight? Then some how I need to address that if the length of the height (taking in account orientation) does not allow it to fit, adapt it so the buttons are closer and scrollable.
You can use sepperate res/layout folders for different screen sizes just like with drawables, examples: layout-small, layout-large etc.
More explained here http://developer.android.com/training/multiscreen/screensizes.html#TaskUseWrapMatchPar
I am trying to create 3 textviews across and 3 textviews down (totaly of 9 textboxes) evenly spaced and when the screen is changed i.e. Landscape and size of screen that they move to adjust the spaces between but the size of the textviews stay the same.
I am real issues i have tried a Linear layout but could get that to work, and then a relative layout neither ... i think the right one is table... but i just can't get it to work.
Can anyone help, i know this must be possible.
thanks
Well if you gave up on RelativeLayout try GridLayout ;)
or better - Vertical LinearLayout filled with three Horizontal LinearLayouts...
However you might wanna use different layout folders to specify which one to use
So in landscape you will one layout and in portrait you use a different layout (both using the same name, located in layout-land and layout-port folders)
Android layout folders: layout, layout-port, layout-land
Android Organise Layouts into Sub Folders
I guess it's the even-spacing that gets you, which is why you might wanna try and do it by using a vertical layout filled with horizonal layouts...
I'm designing a layout that has several buttons and I want the buttons to be all evenly spaced in the menu, and I'm trying to find a way to do this without using any numeric values. If the screen is rotated or the screen size differs I want it all to still be centered.
Here's an example: http://i.stack.imgur.com/yY88p.jpg
Use a weighted LinearLayout. Check out the LinearLayout Tutorial for an example.
Here is a good example. it's adding items programatically.
github