Basically I'm developing a user interface similar to this:
http://ivitto.files.wordpress.com/2008/09/tap-tap-home.jpg?w=160&h=240
Where there are a series of buttons stored in a linear layout. My problem is at the moment they are centered along the x axis and the y axis so they are in the middle of the screen rather than in the lower half of the screen as in the image. The only way I can get what I want to work is by adding 100px or so "top padding" but of course the amount of pixels required is entirely variable on the screen resolution. Whilst this 100px is fine for a 480x320 screen it is far too small for a 1024x600 screen. So basically I'm asking how can I align my linear layout at the bottom of its parent (another linear layout)
Have you tried setting the gravity parameter of the linearlayout to bottom ?
Yes, try gravity bottom.
And by the way. You can use "dip" (density independent pixel ( http://developer.android.com/guide/practices/screens_support.html#density-independence ))instead of px for the padding. Although setting the gravity is surely the nicer way in this case...
Related
I have a problem with layout being cropped when displaying on screens with curved edges. I have a simple layout with some edittexts and a button. The edittexts are cut off on the left side and it only happens on Samsung Edge devices. Can someone know how to deal with these curved edges screen, because adding larger margins seems like a workaround and on flat screens wouldn't look well .Couldn't find anything useful about the issue,.
Thanks in advance.
I believe there are 2 possible solutions to your problem.
WindowInsets: They describe a set of insets for window content. They make it easier to display your UI while taking in to account the system UI and factors of your display.
Guideline: If you are using a ConstraintLayout as your base layout, using guidelines as your horizontal bounds make it easier to design a responsive UI. For example you could set a horizontal guideline at 0.05 percent and another at 0.95 percent, which would keep you content away from the edges, while also keeping your UI responsive at various screen sizes and densities.
The following layout should be achieved and displayed consistently on all screens (phone, tablet, phablet)
Landscape only
Top/left an imageview, always 16:9, probably covering
2/3rd of the width
Right of this a textview, 1/3rd width, full height
(well, maybe a little marigin at to bottom and top aligned with the
image view)
Two buttons on the bottom, left and right aligned
with the imageview.
Any pointer, how that could be achieved? I tried with sw320, sw480 and sw600 layouts, but there is always that one special device, on which the buttons overlap the image....
You can use constraint layout in this case. Constraint edges of all object with each other and edges of the object which is near to the edge, constraint it with layout edge. You can also find more information about this on android developer website or YouTube.
I have read all about supporting different screens and I understand the concept of Density Pixels (DP). However one thing I am not sure about. Lets say I have an image file which is 200 by 200 pixels and I loaded it using xml with wrap_content attributes at the top left of the screen (0,0). Now let's say I want to place a textview programmatically beside it.
If I put the text view at coordinates (250,0). Does that mean that the text view will never overlap the image and will always be to the right no matter what the device density/screen size is.
I understand the distance ( gap) will be different but I am hoping my theory of not overlapping will hold.
I tried it on 2 device and no issues but I am not sure if this is coincendence
Thanks
If you are using px unit it will always remain the same. But if you are using dp unit instead of pixel you cannot definitely be sure.
By the way you should use toRightOf property instead of this approach if you only want this.
I am creating an android app and I am having some trouble with the XML file. What I want is four ImageButtons displayed in the center of four quadrants of the layout (so one in each quadrant). I also want thees ImageButtons to be sized by a percent of the screen (so the button would be bigger on a bigger screen and smaller on a smaller screen) but to a maximum of a specific size.
description of what I have in the layout that works:
The layout that contains thees buttons takes up 70% of the screen height and maximum width (there is another layout in the top 30%) and the screen is locked in vertical orientation. so I'm only looking to complete this quadrant ImageButton style of view.
my attempts to accomplish this was:
1) grid layout: this wrapped my buttons up and they did not take up the whole screen or one quadrant filled up the whole screen and the other three quadrants were not visible.
2) layout dimension percent: several linear layouts positioned in vertical and horizontal orientation and using the layout_hight=0dp (or width), layout_weight="0.50" "trick" to position the quadrants out. This worked nicely but there is a warning i get that the layouts are inefficient when you use a percentage to size a layout within a layout that was position with a percentage, and the ImageButtons did not want to stop at a maximum size completely ignored maxHight & maxWidth (i did have adjustViewBounds="true").
3) I can make all this work easily by calculating sizes and positioning everything by code but I would really like to do this in the xml file and leave that as a last resort.
I would appreciate any help, even a push in the right direction would be grate. I have been stuck on this for a while thank you.
Just do it programatically. It's much simpler as xml is very static and java is dynamic and in complex situations easier to use. Save yourself the trouble.
I am new to xml and android and I was designing a simple application that has 3 buttons in two rows. Now I can't get to a way to make the layout responsive (adjust according to the screen resolution) for every android device. I did a little search but couldn't find anything relative.
So my first question is can you create a UI with xml that works with all sizes of screen?
If yes then how to do it? Or at-least please point me in the right direction.
Thanks
As user Radhe has suggested, android:layout_weight used appropriately within a LinearLayout will easily scale the buttons. If you have the buttons lined up horizontally within a LinearLayout, set each button's height to whatever you'd like (I prefer match_parent) and set each button's width to 0px. For each button, you may set a layout_weight. The weight of each button represents the ratio of the width of each button to every other within that LinearLayout. So if you have 3 buttons, each with a width of 1, the will all be the same width. If one button has a width of 2 and the other two have a width of 1 each, the one with the width of 2 will be as wide as the other two combined. Just play around with it until you get what you like.