how to arrange views in the layout - android

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

Related

Size of my ImageViews is changing between different screen size. RelativeLayout

I'm using a RelativeLayout in the layout of my app.
When I'm choosing different screen size, my ImageViews doesn't keep the same ratio. I'm defining my layout size in hardcoded dp. I think the problem come from the fact that I'm using dp to define my layout and because of that when I'm using my app on different screen with different dpi.
Do you have tips to make my app fits different screen sizes with the same ratio?
Thanks a lot
Please check the height and width of your parent Relative layout , and define each child view with a relation to each other , Or you can move to constraint layout or Linear layout. You should add you layout XML file to understand the actual issue

Using relative layout placement on android

I may be trying to do something that is not possible. I am writing an app that is using a picture of a remote control as its background, and then I am placing buttons on top of the background using relative layout and margins to position the buttons correctly. I thought I would be able to specifiy different margins in different layout files, but it will only take the margins from the main layout file (the one in /layout). I have two layouts for xxhdpi and xhdpi, and the proper graphics are being picked up, but I can't for the life of me figure out how to move them a different amount based on the screen size. I can get one screen size to look fine, but then the other ones are messed up, no matter what I put in the respective xml files. Is it even possible to do this?
Thanks....
you can place the relative layout anywhere on the view in run time. Here is the sample code this may help you.
RelativeLayout DispView = new RelativeLayout(this);
RelativeLayout.LayoutParams DispViewLayoutParams = new RelativeLayout.LayoutParams(w,h);
DispViewLayoutParams.addRule(RelativeLayout.RIGHT_OF, someview.getId());
DispViewLayoutParams.addRule(RelativeLayout.BELOW, someview2.getId());
DispViewLayoutParams.setMargins(x,y,0,0);
Mainview.addView(DispView , DispViewLayoutParams );
You have to create dimens file under various values folders (values,values-ldpi-v6, values-mdpi-v6 etc.) to specify different margins and the system will automatically pick the relevant values based on the screen resolution.
For example
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="call_log_margin">4dp</dimen>
<dimen name="no_call_log_margin_left">10dp</dimen>
</resources>
Use these values "call_log_margin" and "no_call_log_margin_left" in your layouts .These will have different values in different dimens.xml

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.

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

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

Android Screen Orientation

I developed an application in portrait mode in Android.
What changes do I have to do, that my application will be also fit for landscape orientation?
Thanks in advance.
Technically speaking, you don't HAVE to make any changes for it to fit to landscape. It you're using the standard wrap_content and fill_parent for your width and height, your layout will automatically adjust when you change orientations.
With that said, you will often WANT to change to a different layout when switching from portrait to landscape, as a layout that looks good vertically may be unusable when horizontal. You can add a new folder beside your /layout folder titled layout-land. In this, make a new XML file with the same title as your previous layout, and then change the layout from there. Be sure that any and all defined android:ids exist in both the original and landscape layout.
Make sure you use layout_width as "fill_parent" where ever required.

Categories

Resources