Android: how define android:layout_span for height - android

Suppose there are two Button in TableLayout and if I mention android:layout_span="1" in both the button then the complete width is divided into two part and each button sit into one part.
Can we achieve this same thing for height.
In my application four button is there which arranged in linear order one on the top of other.
I want all these four button cover complete height of the screen in any size of screen.
My Problem is here if I launch this screen on one device then it look like:-
But if I launch this layout on big screen then it looks like:-
How on all the screen the button cover(uniformly distribute)?

Set the layout height for each view to be 0 and instead use layout weight. Use the value 1 for layout weight for all the buttons for them to be equally spaced!

Related

How to create matrix of buttons to cover the entire screen

How to actually create a matrix of buttons to cover the entire screen programmatically.
What I tried : I am currently able to create buttons but I want them to occupy the entire screen area, they are just occupying top left part
You can use a TableLayout or LinearLayout too assigning weights in your Buttons.
Let's use a LinearLayout. This can be done both in xml and in your class. Let's create a 2 by 2 matrix of buttons.
Add a LinearLayout with any orientation (let's use horizontal)
Add 2 LinearLayouts inside with opposite orientation of number 1 (in this case we use vertically. Then we set the width=0dp and layout_weight=1 for both to occupy equal spacing)
Now we can add our buttons inside the vertical oriented LinearLayouts and set their height=0dp and layout_weight=1 for them to have equal sizes.
That's it. using the TableLayout is a cheaper way if you have more rows and columns

Make textview take up half of the width of the screen with relativelayout

I have a TextView that I want to have 1/8 of the whole screen, and dp just works to get half of the height but how do I get the 4 TextView's to each share the bottom half of the screen equally?
Right now they share the height equally, but the ones on the left are wider than the ones on the right.
Inside of your RelativeLayout you need to make a horizontal LinearLayout just for these TextView's. Then to make them all take up an equal amount of space, assign an equal weight to them all with weight="1".
If you want a TextView to take up more or less space than the others, just assign a proportionate weight to it. For example if you have 4 views and want the first one to take up 1/2 of the space and the other 3 to share the rest equally, set the weight of the first view to 3 and the others to 1.
You can't with a relative layout- consider a PercentRelativeLayout

Android: how to align element 2 to the right of element 1 while only allowing element 2 to take up as much space as needed

I am trying to align two layouts horizontally but can't seem to get it working. The conditions I need are:
Layout 1 needs to fill up the whole width EXCEPT for the width that layout 2 requires
Layout 2 needs to have a width of 21dp and right / left margin of 17dp.
I can't take a picture because of my job, but here' some ascii art to illustrate what I want:
I attempted using a dummy View between the two layouts so that I could use a relative layout, but that wasn't quite working for me..so any suggestions?
Thanks!
<RelativeLayout layout_width="match_parent">
<Layout1 layout_width="match_parent" layout_toLeftOf="#+id/layout2"/>
<Layout2 id="#id/layout2" layout_width=21dp layout_alignParentRight="true" layout_marginLeft="17dp" layout_marginRight=17dp/>
</RelativeLayout>
Add in the rest of the parameters as needed
Try using a horizontal LinearLayout and set android:layout_weight="1" for layout 2. Like this layout 2 should keep it's size and layout 1 will fill the rest of the available space.

Making buttons take equal height and width of screen

I am currently trying to make a view with four buttons that each take up one quarter of the screen. I know you can use android:layout_weight to set the weight so that the extra space on one axis is filled up, but is there a way to set it so that the height and width are evenly distributed among the four buttons using layout_weight? If not, what is the correct way to do this?
use table layout and create two rows for 4 buttons,determined the height and width
all of these codes are ( XML code)..
should that will working

Designing a layout with multiple ImageButtons and Buttons

I have to make a layout like in the figure below (Each block in the 3 x 3 grid would be a ImageButton and each of the ImageButton has text and a small image in the bottom):-
I think i can use a TableLayout, but the problem is that I want to fit all the components in a single screen without any extra scrolling. When I used LinearLayout, the imageButtons where overlapping each other, how do I avoid it?
I want the ImageButtons to fill up the width of the screen, but match_parent is not helping. Should I fix the size of the ImageButtons. But I want the layout to work in all the screens, not specifically in only one.
If I include the buttons also in the TableLayout (as a separate rows), then they are of the size of the ImageButton, wrap_content is not effective. And I dont know how to place them in the centre.
Please suggest something. Any other layout suggestions? I am not using GridLayout because the App is for GingerBread (Android API 10).
Thank you.
I would use:
- Linear layout, orientation: vertical - as an external layout
- Linear layouts, orientation: horizontal - for each line. Set layout weight for any of the 3 "items" in it to be 33.
Each item consisting of: image button, text and image - a linear layout, orientation: vertical, and the text & image: again, a linear layout, orientation: hortizontal.
Image Button: set width to fill_parent. You can match height accordingly.

Categories

Resources