Updating margin values in view inspector has no effect on layout - android

I am following this tutorial and am unable to make Box Three line up to the top of Box Two (which she shows how to do at around 1:45 in the video).
As you can see in the screenshot, I try setting the top margin to 0 but it has no effect on the layout. If I inspect the value again, I see that it has gone back to 16. I am really unsure what I am doing wrong here as I have been following the video quite closely. The tutorial is quite old from 2016 and I am using the newest version of android studio (bumblebee).
Screenshot of me setting the value to 0 but not having any effect on the display:
How can I make the margin 0??

This is a bug in the latest release: Setting marginTop doesn`t apply when using interface builder, only through XML code. That being said, the issue can be resolved, as you already figured out, by setting the value via 'Declared attributes' from the design view or by declaring the value in your code with
'android:layout_marginTop="0dp"' on your view.

In Box three set height as
android:layout_height="0dp"
then it will will start from top of box two top( both will be equal )

Related

Android Studio can't add elements to the layout

I'm trying to create my first app in Android Studio with Kotlin. The installation worked fine. However if I drag any element onto the Layout, it's not showing up properly. The only change I can see, is a little white dot, that appears as soon as the Layout contains any element. I can select it and view the element attributes on the right, but nothing more.
If I run the app, all elements are squashed in the top left corner.
I already reinstalled Android Studio.
Does anyone know how to fix my problem?
Thaks in advance!
Here is some more information:
XML Code,
Error messages
Make the constraint layout width and height as match_parent in text editor. and then try adding widgets in the design view.
Here is some more information:
XML Code,
Error messages

How do I fix my disorganized objects in my android studio layout? [duplicate]

Every time I create views like Button and TextView in ConstraintLayout, they all get stuck at the top corner instead of where I placed them.
I tried to create new activities and change the emulator, but the result is still the same.
This is a screenshot of what's happening:
What may be the issue?
As stated in Constraint Layout guides:
If a view has no constraints when you run your layout on a device, it is drawn at position [0,0] (the top-left corner).
You must add at least one horizontal and one vertical constraint for the view.
I guess you haven't applied any constraints.
Either manually apply constraints to the view, or let the layout editor do it for you using "Infer constraints" button:
When you drop a view into the Layout Editor, it stays where you leave it even if it has no constraints... this is only to make editing easier
In other words, the View will "stay where you leave it" until you add constraints.
The reason it looks different in the Preview vs your app is because anything in your XML with tools: is going to be removed from the code when your app runs. These options are only for the Android Studio layout editor, not representative of what you should expect to see when the code runs.
And it may be troublesome for beginners because
a missing constraint won't cause a compilation error
However
the Layout Editor indicates missing constraints as an error in the toolbar. To view the errors and other warnings, click Show Warnings and Errors (red button with number). To help you avoid missing constraints, the Layout Editor can automatically add constraints for you with the Autoconnect and infer constraints features
More details
A quick, easy way to fix this is to click on the component (TextView, ImageView, etc.) and click the infer constraints button. It looks like 2 yellow plus signs.
infer constraints image
add this in xml to the button etc
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.57"
then play with it in the design.
Good luck! :)
Basically this type of problem happens when you use ConstraintLayout .
So Go to Preview From Android Studio.
Select That button you want to set at the specific position
At last just click the infer constrains button as i mention in
the picture below on a red circle.
Thats All run the project and see magic
Thank you

My button is over my text in android layout? [duplicate]

Every time I create views like Button and TextView in ConstraintLayout, they all get stuck at the top corner instead of where I placed them.
I tried to create new activities and change the emulator, but the result is still the same.
This is a screenshot of what's happening:
What may be the issue?
As stated in Constraint Layout guides:
If a view has no constraints when you run your layout on a device, it is drawn at position [0,0] (the top-left corner).
You must add at least one horizontal and one vertical constraint for the view.
I guess you haven't applied any constraints.
Either manually apply constraints to the view, or let the layout editor do it for you using "Infer constraints" button:
When you drop a view into the Layout Editor, it stays where you leave it even if it has no constraints... this is only to make editing easier
In other words, the View will "stay where you leave it" until you add constraints.
The reason it looks different in the Preview vs your app is because anything in your XML with tools: is going to be removed from the code when your app runs. These options are only for the Android Studio layout editor, not representative of what you should expect to see when the code runs.
And it may be troublesome for beginners because
a missing constraint won't cause a compilation error
However
the Layout Editor indicates missing constraints as an error in the toolbar. To view the errors and other warnings, click Show Warnings and Errors (red button with number). To help you avoid missing constraints, the Layout Editor can automatically add constraints for you with the Autoconnect and infer constraints features
More details
A quick, easy way to fix this is to click on the component (TextView, ImageView, etc.) and click the infer constraints button. It looks like 2 yellow plus signs.
infer constraints image
add this in xml to the button etc
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.57"
then play with it in the design.
Good luck! :)
Basically this type of problem happens when you use ConstraintLayout .
So Go to Preview From Android Studio.
Select That button you want to set at the specific position
At last just click the infer constrains button as i mention in
the picture below on a red circle.
Thats All run the project and see magic
Thank you

New to android development, main activity widgets appear randomly on equator compared to design view [duplicate]

Every time I create views like Button and TextView in ConstraintLayout, they all get stuck at the top corner instead of where I placed them.
I tried to create new activities and change the emulator, but the result is still the same.
This is a screenshot of what's happening:
What may be the issue?
As stated in Constraint Layout guides:
If a view has no constraints when you run your layout on a device, it is drawn at position [0,0] (the top-left corner).
You must add at least one horizontal and one vertical constraint for the view.
I guess you haven't applied any constraints.
Either manually apply constraints to the view, or let the layout editor do it for you using "Infer constraints" button:
When you drop a view into the Layout Editor, it stays where you leave it even if it has no constraints... this is only to make editing easier
In other words, the View will "stay where you leave it" until you add constraints.
The reason it looks different in the Preview vs your app is because anything in your XML with tools: is going to be removed from the code when your app runs. These options are only for the Android Studio layout editor, not representative of what you should expect to see when the code runs.
And it may be troublesome for beginners because
a missing constraint won't cause a compilation error
However
the Layout Editor indicates missing constraints as an error in the toolbar. To view the errors and other warnings, click Show Warnings and Errors (red button with number). To help you avoid missing constraints, the Layout Editor can automatically add constraints for you with the Autoconnect and infer constraints features
More details
A quick, easy way to fix this is to click on the component (TextView, ImageView, etc.) and click the infer constraints button. It looks like 2 yellow plus signs.
infer constraints image
add this in xml to the button etc
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.57"
then play with it in the design.
Good luck! :)
Basically this type of problem happens when you use ConstraintLayout .
So Go to Preview From Android Studio.
Select That button you want to set at the specific position
At last just click the infer constrains button as i mention in
the picture below on a red circle.
Thats All run the project and see magic
Thank you

ConstraintLayout views collapse [duplicate]

Every time I create views like Button and TextView in ConstraintLayout, they all get stuck at the top corner instead of where I placed them.
I tried to create new activities and change the emulator, but the result is still the same.
This is a screenshot of what's happening:
What may be the issue?
As stated in Constraint Layout guides:
If a view has no constraints when you run your layout on a device, it is drawn at position [0,0] (the top-left corner).
You must add at least one horizontal and one vertical constraint for the view.
I guess you haven't applied any constraints.
Either manually apply constraints to the view, or let the layout editor do it for you using "Infer constraints" button:
When you drop a view into the Layout Editor, it stays where you leave it even if it has no constraints... this is only to make editing easier
In other words, the View will "stay where you leave it" until you add constraints.
The reason it looks different in the Preview vs your app is because anything in your XML with tools: is going to be removed from the code when your app runs. These options are only for the Android Studio layout editor, not representative of what you should expect to see when the code runs.
And it may be troublesome for beginners because
a missing constraint won't cause a compilation error
However
the Layout Editor indicates missing constraints as an error in the toolbar. To view the errors and other warnings, click Show Warnings and Errors (red button with number). To help you avoid missing constraints, the Layout Editor can automatically add constraints for you with the Autoconnect and infer constraints features
More details
A quick, easy way to fix this is to click on the component (TextView, ImageView, etc.) and click the infer constraints button. It looks like 2 yellow plus signs.
infer constraints image
add this in xml to the button etc
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.57"
then play with it in the design.
Good luck! :)
Basically this type of problem happens when you use ConstraintLayout .
So Go to Preview From Android Studio.
Select That button you want to set at the specific position
At last just click the infer constrains button as i mention in
the picture below on a red circle.
Thats All run the project and see magic
Thank you

Categories

Resources