If a button of elevation=5dp is attached to a LinearLayout of elevation=5dp,
Do we still see the button as being on the same level as the LinearLayout or 5dp above it?
Yes you can see the button as being on the Linear layout. As Button is in linear layout, layout will be on 5dp elevation from the screen and Button will be on 5dp elevation from linear layout.
Esentailly the elevation is Relative.
The elevation affects the view and the entire sub-collection of the view
So, when we increase the view of the widow to 5dp elevations, the button also drops to 5dp, and the 5dp buttons make the parent 5dp higher.
Related
On an activity in a LinearLayout I have a number of controls most of which are EditText. I wonder, is there any way to set margin or padding for those controls in one fell swoop instead of having setting it for each control one by one?
Add the margin or padding to the LinearLayout itself. On doing so then the margin and padding will apply for all its child views.(The Edit Texts)
Im running into a speed bump in my android App. I want to center my Linear Layout in the center of the screen (Horisontally only) and I want to center another element only vertically. I haven't seen an easy apparent way to do this in the program.
http://i.stack.imgur.com/gfMBD.png
I want the grey Box to be centered horisontally in the app
I'm not sure, how your layouts are now, but I'd do something like this:
Vertical Linearlayout
RelativeLayout, centered horizontally
RelativeLayout, set to match parent
RelativeLayout, centered vertically
Use RelativeLayout as a root ViewGroup, and then just add android:layout_centerHorizontal="true" to your first LinearLayout, and android:layout_centerVertical="true" to your second one.
I just started Android development and I'm having trouble figuring out why my text alignment inside my button isn't horizontally centered. It is vertically centered.
I've tried gravity, some padding, center, and text alignment center with no luck. I am using a RelativeLayout with an EditText and a TextView above. When I take the other views out of the activity, there is also no change.
I can get it to center with gravity center_vertical and some padding left, but this method seems inappropriate.
Here is a view of the button before update:
Update: Tested on my ADV for android:gravity="center_vertical|center_horizontal" and it ended up working fine. Seems to be a bug with the Graphic Layout view in Eclipse that is mis-aligning the inner context of the Button view. Here's it working on my AVD:
Set the gravity of the button as android:gravity = "center" or android:gravity = "center_vertical|center_horizontal" .
try layout_gravity="center" or gravity="center" instead. I always forget which one : P
android:gravity = "center"
will align the text inside the button both horizontally and vertically.
android:layout_gravity is different from android_gravity.
Refer for a detailed answer:
Gravity and layout_gravity on Android
I want to make an about button in the top left. I tried:
android:layout_gravity:"top|left"
but it doesn't work , I searched and all what I found was using RelativeLayout and if I use that I'll have to make all my layout from beginning and it's not that good like the linear layout.
Couldn't post the code here. So this is my code on pastebin
http://pastebin.com/5EjgyB0K
Here you have given android:layout_gravity="center" to the Linear Layout so it is going to set gravity of the layout and as center and your About Button is child of layout its to going to set in center and you have given Margin_top also.Try to remove gravity amd Margin_top and you can see the result, the button will be top|left of the screen.
I have a button on a relative layout that hugs the buttom of the parent, but since there is not much above the button, the height of it is massive and extends to the object above it. What kind of code can I use to make sure the button stays at a normal height while still hugging the bottom of the parent?
set the height to wrap content