Android: Layout trying to insert 3 textviews across and 3 squares down - android

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...

Related

how to arrange views in the layout

What is the best approach to arrange four views in layout ?
In portrait mode I would like:
On screen rotation to landscape I would like to change layout with animation to
How I should to arrange these views ? I'm thinking about 2 LinearLayout's and to change after roatation to one LinearLayout with horizontal orientation.. Or GridLayout ?
I would provide two layout files. The portrait has 3x LinearLayout
v
-h
-h
and landscape just one horizontal.
In terms of performance you should not fear a difference.
Just use two different layouts and create a refs.xml file in your nornal values folder, if you don't have one already, in that do something like;
<item name="plus_buttons" type="layout">#layout/plus_buttons_small_grid</item>
And then for screenwidths that you think the horizontal arrangement will fit perfectly, say 600dp, create a folder called values-sw600dp in your res directory and do something in another refs.xml in that folder like this;
<item name="plus_buttons" type="layout">#layout/plus_buttons_large</item>
With this you have two layout files that are independent of each other and work for all the desired screen widths

Which layout to use and how to achieve the following?

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

Change layout at autorotation

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.

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.

Relative stacking with Linear Layout in Android?

I have 6 images I want to display as 2 rows with 3 images in each. I'm using nested LinearLayouts to achieve this, and it works well except for one thing:
The height of the largest image dictates the size of the linear layout, meaning there is empty space a lot of the time. In other words, my problem is as follows:
I keep getting the layout shown on the left, and I want the layout shown on the right.
I am aware that you can just use GridView, but that will still prevent the exact layout shown on the right, so I'm at a loss really. Many thanks.
Instead of 2 rows of three columns, you need 3 columns of 2 rows. LinearLayouts would be fine, just to be sure set the Gravity of the individual cells to Gravity.TOP.
You could equally achieve the whole grid using RelativeLayout instead of Linear. Each of your bottom row would just need android:layout_below and android:layout_alignLeft set to be the ImageView above it.

Categories

Resources