Android Studio can't add elements to the layout - android

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

Related

Updating margin values in view inspector has no effect on layout

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 )

Android studio My app is displaying incorrectly.

I am trying to learn to make my own apps by following tutorials but i have an issue when i run the app in the emulator or on my phone. All theScreenshot contents of the layout are squished in the top left corner.
This is all the codescreenshot 2here. I am a noob so don't go to hard on me. Thanks
It would be better if you also post your layout code (activity_main.xml) here for this kind of problems. But I am guessing you are using constraint layout as root of your layout and its child views are not constrained vertically, so all of them go to another position in run time.
Maybe you are using a relative layout and no positioning is specified.
You should paste the xml's code

Buttons not visible on the application. What's wrong?

I created an empty activity for 'My Testing App' and it looks like the following in the preview section:
But when I generated a build apk and used the same in my cell phone the result was like the following:
I can only view the exit button on the very top left but the two other buttons, that should be above it are missing.
I tried to rearrange the icons on the screen as well. I made them to go to the bottom, to the right most, but I see no change when the apk is reinstalled.
How do I make them visible on the hardware?
Here is the snap of the code for this activity:
To quickly add constraints to your layout just click on the Infer Constraints button in the Layout Editor toolbar. Learn more about the feature here: https://developer.android.com/training/constraint-layout/index.html#use-autoconnect-and-infer-constraints
Right Click on you Layout and select "Convert View" Option.
then select "LinearLayout" Option.
it will show all three buttons in the output.
You have to learn about ConstrainLayout in Android
View in ConstrainLayout is not only drag and drop. You should link the constrain line in each view to reference with somewhere on the screen.
Any XML attributes prefixed with tools are removed when the app is compiled and are only rendered by Android Studio layout editor.
You need to properly set constraints in your ConstraintLayout, not use absolute positioning.
Or you may instead use RelativeLayout, LinearLayout, etc.
https://developer.android.com/training/constraint-layout/index.html
Start by reading this. Most of what you need is answered here. The problem is that your views are not properly constrained (basically they aren't linked to anything so when you run your app it doesn't know where to place them and just defaults to the upper left).

Blueprint view nor the constraints are now visible in Android Studio design view

I had to edit the Constraint Layout XML file by hand (*), so I also removed all the tools: fields from the XML. To my understanding these attributes are only used by Android Studio and the Constraint Layout tool. But I removed them because I wanted to reset the state of the layout and changing the android: properties for the Constraint Layout surely would only mix things up even more, right?
So I am now in a situation where the blueprint view stays empty and the hierarchy view says "Nothing to show". I see no view properties and no constraints. I can only see the flat UI design view of the layout, but I can't select any elements from it either.
Any ideas how to fix this?
I am running Android Studio 2.2.3 and Constraint Layout beta 4.
*) Why did I edit the layout by hand you ask? Well, I selected "Convert to Constraint Layout" in which case Android Studio just flattened my layout and hard coded the positions of all elements. Which wasn't exactly what I wanted since then I couldn't change the positions anymore. Removing the hard coded positions (and the tools: arguments) let me re-structure my layout.
Ok, I am going to answer this myself since I got it working thanks to Nicolas Roard who works on the Constraint Layout team at Google.
try pressing "r" [in the design view]
https://twitter.com/camaelon/status/809427379500126208
I wasn't aware of the keyboard shortcut "r" in this case, but it did solve it for me!

Recently Android studio 2.2 - Unable to drag views around in layout file

I updated to 2.2 literaly 30 minutes ago and when I tried to move widgets around in layouts,
this happened:
https://gyazo.com/d3c640cca6f212aaa9effe2db9bccb98
I can't center it or even move it to the right,center,etc. It's always stuck on the left.
What's wrong with it? any ideas? should I uninstall Android Studio and re-install it again?
You Should Post your layout.xml file here, But i think you should go and change the layout in the layout file from linerlayout to the Relative Layout .
Linear Layout puts widgets one after the other.
Relative Layout puts stuff or widgets relative to the other widgets on the page or the relative things like centre of the page or 5dp below another widget.
Hope it helps :)

Categories

Resources