How to set layout margin on Android Studio 3.4? - android

Trying to do this android tutorial,
Drag a Plain Text (EditText) element from the Palette pane to the
bottom of the layout, and add constraints to the left side of the
layout, the bottom of the layout, and the left side of the Send
Button. Set its attributes in the Attributes pane as follows:
Attribute
Value
id
editText_main
Right margin
8
Left margin
8
Bottom margin
16
But I do not see a way to set the layout margin. When I select the editText_main and input 8dp into the layout_marginLeft, and press Enter or Tab, the number 8dp disappears. It was swallowed without a burp.

It was not obvious, but I right clicked and then selected the Constrain menu and added constraints. Then I went into Attributes and it allowed me to modify the current value.
It seems like a design bug.

I'd advise you not to use the drag pane only, Some features are much easier with the xml editor
Goto you xml file add margins like this.
<EditText
android:layout_marginBottom="16dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp" />

It is not a bug, a constraint layout child CANNOT have a child with margins because it has a set position (if you just drag and drop it from the palette), the position wont change no matter what, so adding margins is useless, when its constrained those margins become useful because lets say i constraint a button to the left but i don't want it completely to the left, so lets add a marginLeft of 8 dp, in that case it is relevant to have a margin thats why the editor wasn't letting you add them until you constrained it.
You can see this in the "Text" tab, the position is absolute, margins are useless when the position is absolute. So the editor prevents you from adding them.
Whenever you add a constraint to it the editor gets rid of the absolute position and lets you add margins.
Maybe your tutorial didn't specify what layout to use since it used to not be relevant until constraint layout was implemented.

Related

I cant move any elements in the layout (Android Studio)

I cant move any elements in the layout (android studio) for some reason..
I searched alot and nothing worked with me.
All text views or buttons (all elements) stays top-left and I cant move them or even resize them...
Whats the solution for that?
And if I tried to resize the button it fills up the whole screen.
thats the code view
This is happening as you have used constraint layout in your XML file.
and the constraints as you have given in your file that makes your elements stay up at the top left.
Solution 1:
When you give start to start constraint to the parent and end to end constraint to the parent it makes your view to stick to the both side of the screen.
Even if you have given your view's height and width to wrap content it will be considered as match parent.
<androidx.constraintlayout.widget.ConstraintLayout ...>
<Button android:id="#+id/button" ...
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</>
as This will make your view to stretch to the both side of the screen and will take whole space horizontally.
all you need to do is remove the constraints mentioned below:
if you want to let your view to stick to the left side of the screen-
Remove EndtoEndof = parent constraint
if you want to let your view to stick to the right side of the screen-
Remove StarttoStartof = parent constraint
The issue with resizing the button is that you have given the constraints to the view to stick to bottom and top of the screen so it will take up whole screen vertically.
if you want to make your button to stay to the bottom
Remove toptotopof = parent
if you want to make your button to stay to the top
Remove bottomtoBottomof= parent
all you need is to understand how constraint layout works .
Look into this link it will help you understand the constraint layout from broad perspective.

Eclipse android can't make views bigger

If i try to make the thing u see in the screenshot it just falls back to original size. I can't change sizes of any view Objects. Anybody knows a fix?
http://imgur.com/2S1xoLP
In Eclipse (as you're using the designer), you can set the Width and Height of a View, within the Layout Parameters section of the Properties pane. This can be set to wrap_content, match_parent or fill_parent.
You can also do this within the XML markup of the activity you're editing. Click the .xml tab at the bottom of your designer, and you'll see all of the XML that makes up your activity. Once in there, find the problematic view and add:
android:layout_width="match_parent"
android:layout_height="match_parent"
Edit
Also, when inside of a RelativeLayout, it's possible that Eclipse will add default padding values, so regardless of what you set, your View's wont reach the parent layout's edge, until you remove them. Just FYI!

Bottom margin Android LinearLayout item in XML ignored, but works in Java code

I am developing an app with an activity with member reactions on a hike event. The reactions are the yellow "balloons" which are made using a LinearLayout. Each item is constructed from a XML file (listitem_deelnemerreactie.xml) which defines the layout for a reaction item. The top level of this layout file is a LinearLayout my itself.
I want some spacing between the separate elements, as well as some right margin. The most straightforward way to so this should be: setting a bottom and right margin on the top-level LinearLAyout element of the listitem_deelnemerreactie.xml layout file.
But setting the bottom margin on the LinearLayout has no effect on the vertical spacing, though the right margin does have an effect.
The only way to be able to set a vertical margin appears to be: setting is in the Java code, after attaching the inflated view to the container.
See the two images for the effect and the code.
Though setting the margins in the code is a working workaround, I still think it is strange this cannot be achieved in the XML. Why is the bottom margin attribute ignored while the right margin is not?
Any ideas?
Have you tried to set an android:padding="10dp" for example on your elements to spaced them ?

Android top left button

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.

Removing the margin from bottom in android Relativelayout

Hello i have used a Relativelayout in android using XML but when i see image in graphical layout there is small margin left at bottom in different screensizes.How to remove that margin.I also used a ScrollView in layout.
I think you have to set bottom margin in negative
like
android:layout_marginBottom="-10dip"
Check whether you have used padding for your layout,
Better post your layout file and/or screenshot.

Categories

Resources