Which layout to use and how to achieve the following? - android

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

Related

Arranging Components in App Inventor?

Is there a more precise way of arranging components in App Inventor than using the Vertical/Horizontal/Table Arrangement formatting elements?
I want to sparsely position about six buttons across my app screen - all different sizes.
Thank you in advance.
the short answer is: no
well, additionally you also could use empty labels as delimiter between components...
another answer is: you could use a canvas and sprite components instead of buttons. You can define sprite positions exactly at x/y coordinates of your canvas.
However keep in mind, that there are different Android devices with different screens sizes and resolutions, so normally you wouldn't set buttons exactly at x/y coordinates to avoid strange layouts for e.g. smaller or larger devices.
The bit longer answer is to use labels as spacers.
Example:
Need to center a button at the top of the screen.
Add horizontal layout with 2 label texts and button in center inside of the layout.
Click each text label and remove the actual text from right side properties menu and choose fill parent width and height.
This centers the button because the layout automatically assigns one third size to each.
Labels are the best, but longer coding answer.

Android layout that crops rather than resize its children

I am looking for an android layout (if there exists) that can do the following.
2 images that occupies the entire width of the screen, stacked on top of each other. A slider say 2 or three pixels wide that allows a user to slide across the width of the screen revealing or hiding portions of the images.
Note that the layout like slidingPane does not work in this scenario as it resizes the contents in each pane rather than cropping them which is what I want.
To better describe the question here are some images.
Not really a layout, but achieves what I was after.
Added images to textureviews(1,2), added one of the textureviews(2) to a linearlayout. Added the texureView1 and linearlayout to a framelayout such that the linearlayout is on top. To achieve the above said effect the linearlayout and the textureView(2) that it holds is moved in opposite directions.

Which layout is suitable for all Android mobile?

I am developing one application, right now i am on designing phase. i design one screen
on the 3.7WVGA(Nexus One) screen in eclipse using Linear Layout. but when i test it on 2.7
my some icon are go outside of the screen. my question is that which layout is suitable for all screen whether i design it in 3.7 inch or run it on 2.7.
Please give me a suggestion.
Thanks in Advance.
1st i design it in 3.7 and second in 2.7.
Don't ever, ever, ever design a screen for Android based on an actual screen size. You will always screw yourself up because there are a hundred different screens out there. What looks good on one phone will look like crap on another. That being said, here are some tips:
Use RelativeLayout to lay your button contents out. Once you understand the model it's much easier than you suspect and it will make it easy to automatically scale things.
Only use actual pixel sizes for things that "float". You never want to specify the width of something and try to fill the width of the screen.
Include multiple resolutions of your images. Let the system pick the right resolution for you.
A table/grid layout will make things easier for you on the overall design.
Big panels of buttons are played out. There are other UI options at your disposal (menu buttons, swiping left and right through screens, etc.). When users see a field of buttons it looks like the app was slapped together.
For that kind of layout use GridView if you want it scrollable, or a simple RelativeLayout if you want all the elements to scale depending on the size of the screen (use toRightOf, toLeftOf, above, below and weight to achieve that)
You need to consider the guide provided by android
Multiple Screen Support
What you will do is to provide all screens icon regarding different screens and you can also specify layouts for different screens, for example you want to provide drawables and layout for multiple screens, you will provide resources in that specific folder + below suffix.
Screens for layouts for drawables
ldpi layout-small drawable-ldpi
mdpi layout drawable-mdpi
hdpi layout-large drawable-hdpi
xhdpi layout-xlarge drawable-xhdpi
This topic will be more relavent to your need.
The following are the view groups in android. you can use any of these as per your requirement. But in your case You can use GridView
View Groups in android
FrameLayout Layout that acts as a view frame to display a single
object.
Gallery A horizontal scrolling display of images, from a bound
list.
GridView Displays a scrolling grid of m columns and n rows.
LinearLayout A layout that organizes its children into a single
horizontal or vertical row. It creates a scrollbar if the length of
the window exceeds the length of the screen.
ListView Displays a scrolling single column list.
RelativeLayout Enables you to specify the location of child objects
relative to each other (child A to the left of child B) or to the
parent (aligned to the top of the parent).
ScrollView A vertically scrolling column of elements.
Spinner Displays a single item at a time from a bound list, inside
a one-row textbox. Rather like a one-row listbox that can scroll either horizontally or vertically.
SurfaceView Provides direct access to a dedicated drawing surface.
It can hold child views layered on top of the surface, but is intended for applications that need to draw pixels, rather than using widgets.
TabHost Provides a tab selection list that monitors clicks and
enables theapplication to change the screen whenever a tab is clicked.
TableLayout A tabular layout with an arbitrary number of rows and
columns, each cell holding the widget of your choice. The rows
resize to fit the largest column. The cell borders are not visible.
ViewFlipper A list that displays one item at a time, inside a
one-row textbox. It can be set to swap items at timed intervals,
like a slide show.
ViewSwitcher Same as ViewFlipper.
I have the same problem but i found a very simple solution is use dp and sp instead px. You may read this:
What is the difference between "px", "dp", "dip" and "sp" on Android?
And you may create icons with different resolution and put it in suitble folder.
create a table layout and every row contains a vertical linear layout put all buttons inside and provides weight to each button according to need,at the last put this table layout to ScrollView that is suitable for all android devices
I created a tool that allows you to scale/adjust your layouts for tablets and small screen devices and made a blog post about it here: http://onemanmobile.blogspot.com/2012/04/how-to-scale-your-android-layouts-to.html
Basically, defining your layouts in dp units for one size is not enough if you want your app to fit on all devices and tablets, since there's four different "density-buckets". This tool will allow your layouts to be converted into fitting these density buckets.
It also explains in further detail how to make more flexible layouts for all resolutions.

Distribute multiple items evenly throughout a dynamic space

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

Evenly spacing views within adjacent layouts

I'm working on the controls for a game, and require part of the control panel (gray in the figure below) to change dynamically, either showing a single canvas (left) or 5 buttons (right). The border between the lower-row views should always be positioned at exactly the same x-position as the border between the buttons on the upper row, as shown. At the same time, all twelve upper buttons should be scaled and distributed evenly.
I've considered several approaches, but as of yet none do all of what I want:
Using two LinearLayouts, one for each row of controls: reliably aligning the borders seems to be impossible, and replacing part of the layout is difficult at best.
Using a TableLayout: again, replacing a portion of the layout is difficult.
Using a RelativeLayout: resizing and aligning buttons independently of the screen size doesn't seem possible
Any suggestions for an alternative method, or on how to make one of the above approaches work? It would also be nice if there were some way to animate the change of views, i.e. sliding in the buttons from the left over the canvas. Thanks!
Interesting, I've done this several weeks ago. What I did is to make use of this property of View object: "Visibility". So that means at a fixed position, I can set any View to display on to, not depending on any type of Layout, it can be Visibility.GONE, Visibility.VISIBLE or Visibility.INVISIBLE.
In my app, I used RelativeLayout to set relative position to the right side TextView.
Give it a try :)
In order to close this question: I have solved the problem by writing a custom layout class that places and sizes the child views without heeding the measured size of the children. Effectively this gives me the behavior of a linear layout with layout weights, but is more deterministic with border placement.
A ViewAnimator is used to switch between the Canvas and the Buttons.

Categories

Resources