Android Studio will not allow me to make chains - android

I am following the "getting started"-tutorial on the android studio website.
(Link: https://developer.android.com/training/basics/firstapp/building-ui.html#button)
When the tutorial told me to make a chain between the views, I just could not make it work. When i tried to drag a constraint from the editText view to the button view, the constraint anchor on the button turns red and will not allow me to connect the constraint.
I have already tried to manually edit the XML code by adding app:layout_constraintLeft_toLeftOf="#+id/button" under the editText view, but that does not work. I have also tried to delete everything and start from scratch several times, but that does not work either.
Current layout (blueprint view)
Any help would be appreciated!

You appear to be running into a known bug with the ConstraintLayout editor in Android Studio.
See:
https://issuetracker.google.com/issues/37325425
and
https://issuetracker.google.com/issues/37137698
You should be able to create a chain by using the "center horizontal" or "center vertical" commands applied to a collection of views which are currently selected in the editor.

Related

Get the Xamarin Android Designer to work with the Toolbox

This question is about Xamarin Android which supports drag and drop functionality, not Xamarin Forms.
When using the Xamarin Android Designer in Visual Studio I am only allowed to drag in one control from the toolbox. After this, I am no longer able to add any new buttons (with the cursor changing to a "not allowed" symbol when trying to drag in a new button).
Steps to reproduce the problem:
Create a new Xamarin Android App project in Visual Studio.
Navigate to the "Resources/layout/activity_main.axml".
Try to add two buttons to the Design. Trying to add the second one will show the "not allowed" symbol in place of the cursor.
I've looked online for a solution, including Xamarin Community Forums and the Visual Studio Developer Community and but have only found posts on the same or similar issue with no solution that has worked for me. How can I solve this?
RelativeLayout in Xaml doesn't allow drag&droping more than 1 control by design.
RelativeLayout is a ViewGroup that displays child View elements in relative positions. The position of a View can be specified as relative to sibling elements (such as to the left-of or below a given element) or in positions relative to the RelativeLayout area (such as aligned to the bottom, left of center).
Basically, designer let you add only one control on which you design your interface. You position the other controls from Xaml based on original dragged control.
You can drag&drop controls from toolbox directly to Xml code and it allows you to edit further the control from Properties box.
Also, https://developer.android.com/guide/topics/ui/layout/relative officially recommends to use ConstraintLayout instead.
If you insists to use RelativeLayout, you will have to code the interface in Xaml.

App doesn't format elements at all & just shows them all in one line

I just downloaded Android Studio and decided to try it out, never programmed in Java, or any kind of android app. It all seems good but once I emulated the app. I got weird formatting that wasn't a thing in app preview when I coded it. This is a simple "squaring" function app.
When I look at the preview:
When I emulate it:
You are getting this kind of formatting because you are using Constraint Layout as your root layout. There are no constraints to the views(EditText, Button and others) because of which they are placed at the top left corner of the screen.You have to add constraints in ContraintLayout.
Follow any of the three methods below-
Learn about Constraint Layout. Check out this link -Build a Responsive UI with ConstraintLayout in Android Studio (Most Useful of the three)
Change Constraint Layout to Linear Layout or Relative Layout as your root layout.(if you are familiar with them)
Click Infer Constraints (orange color two stars type symbol ) to automatically create constraints and compile again.(Simplest of the 3 methods for you right now)

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!

Trouble Dragging Android Views

I'm trying to learn Android development and using the Android SDK in Eclipse. I'm following a tutorial to build the Main.XML file on the Graphical Layout tab. It instructs me to drag several Views onto the screen surface, including: EditText, Button, RadioGroup and RadioButton.
My issue is that these Views do not seem to drag. I place the mouse cursor over them, press the right button but the Views are not captured for dragging. There are other Views (such as Gallery) that seems to drag OK but those I'm interested in (to complete the tutorial lesson) do not drag.
Any help making this work properly would be appreciated.
Forget about dragging Android elements. The best approach is to hand code them. Eclipse helps a lot, since it can show you a preview of what you wrote.
you can try to edit the properties of the button i do believe that eclipse lets you do that
Goto Help->Check for New Updates and update
And then, You'll be able to drag n drop the View components onto your xml Graphical Layout. As #MEGA said, its advisable to hand code them. But, still as a beginner, I use Graphical Layout and the set properties using the Properties tab, which is more handy (since we donno what each property is for!)

Categories

Resources