How to make a View to fill the space between two views? - android

I want to layout my views in the following way: [Button] [SomeView] [Button]. I want to set specific sizes for buttons (in mm), and then have the SomeView fill the remaining space between them.
How to achieve this?

Maybe you could set the layout:weight of the [SomeView] to 1 and put all of these views in a linearlayout. Hope it works!

Related

Leave blank line in Linear Layout

I am developing for android. The app is designed in XML in Linear Layout. What I want to do is to leave some blank lines between the consecutive buttons/text to ensure some neatness in the GUI. Is it posible to do it in Linear Layout? Please help...
You should use margins to seperate different components in your layout. An example of how this would look in your XML is: android:layout_marginTop="12dp"
If you want to leave space outside the border of text/button and next view elements you can use android:layout_marginLeft, android:layout_marginRight, android:layout_marginTop and android:layout_marginBottom.
If you want to leave space between border of the text/button and actual content of the text/button you can use android:paddingLeft, android:paddingRight, android:paddingTop and android:paddingBottom.
For more info check out this question
how to increase the space between the elements in linearlayout in android?

Android: How to change Relative Layout to Scroll Layout

Hello i have an Relative Layout in Android, with EditTexts, TextViews, one Spinner and RadioButtons. It's a lot of things for only one screen, so i need to change for a ScrolView. When i try add the line in the first line and on the last Row, I have problems.
How can i add a scroll on my screen without lose all the layout I built so far?
so i need to change for a ScrolView
You do not need to change "for a ScrolView". You need to wrap your RelativeLayout in a ScrollView.
How can i add a scroll on my screen without lose all the layout I built so far?
Put a ScrollView around your RelativeLayout:
<ScrollView>
<RelativeLayout>
<!-- existing stuff here -->
</RelativeLayout>
</ScrollView>
As #CommonsWare has said, you can just wrap your current layout with a ScrollView.
Just keep in mind that a ScrollView must have only one child.

How to fill the remaining space between two layouts

I've got a problem concerning android layouts.
In my xml file I have two relative layouts. One is attached to the top by android:layout_alignParentTop="true".
The other one is attached to the bottom by android:layout_alignParentBottom="true".
Now there's a lot of space between these two views. I'd like two fill this remaining space with a FrameLayout where a couple of different fragments should be displayed.
Does anybody know how to fill the space I described?
Thanks a lot!
<FrameLayout android:layout_below="#+id/toplayout"
android:layout_above="#+id/bottomlayout"/>
add your frame layout and set its property
< android:layout_above="#+id/top"
android:layout_below="#+id/bottom" >
so the frame layout will occupy thw whole space between these two layouts

Views taking equal share of Layout

I've created a custom dialog builder that contains 2 buttons.
Depending on the dialog's setup, I may choose to hide one of the buttons completely, using Window.GONE.
Ideally what I want to happen is:
1. If there is only one button, then fill the layout with it
2. If there are two buttons, then split up the space in the layout equally with these
Is it possible to do this without having to work out the width of the dialog, the number of buttons and then set the sizes manually?
I was hoping there may be a neater way to perform this
ok, here is how I would do it:
<LinearLayout layout_width:fill_parent layout_height:wrap_content>
<Button
layout_width=fill_parent
layout_height=wrap_content
layout_weight=1/>
<Button
layout_width=fill_parent
layout_height=wrap_content
layout_weight=1/>
</LinearLayout>
The trick is to put both elements a width of fill_parent and a weight of 1. If they are both drawn, they will each take up half the screen. If you use View.Gone, one of them will disappear and the other should take up all the space.
yes of cource put your views means button in linear layout and give yor buttons equal layout_weight will solve your problem.

Best android layout for a set of columns

On an Android layout, I'd like to have a set of rows, each with two TextViews. The leftmost column of TextViews should be right-aligned, just left of an imaginary centerline down the screen. The rightmost column should be left-aligned.
Examples of this can be seen at http://stuff.greenberg.org/ScopeCalc.htm
What's the best layout to use?
IMO, TableLayout would be a logical choice with appropriate use of colspan/rowspan.
You can also do this using LinearLayout, with the two sub-views of each row each getting 50% of the width.
Using GridLayout you can apply columnspan and rowspan properties to the views inside the grid.

Categories

Resources