Get the Xamarin Android Designer to work with the Toolbox - android

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.

Related

Android Studio will not allow me to make chains

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.

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)

Dragging and Dropping a button from one Linear Layout to another Linear Layout

I have a linear linear layout with 10 buttons in it. I need to drag these buttons and add it into another linear layout(Horizontal) in the order they are dropped. Please help me in doing this?
I have some suggestions on how to do drag-drop in apps running on API level 8 up and beyond. I studied the source code for the Android Launcher module and learned about the drag-drop framework they put in place for that. I have found that is a good foundation on which to build. I have written up the details of the key classes (DragSource, DropTarget, DragLayer, DragController) in a series of articles on my blog. A solution is too long to post here, so I refer you to those notes:
(a) Moving Views In Android - Part 2, Drag and Drop - this describes the basic framework and includes a demo app. Since I was primarily concerned with learning about drag-drop, I used the now deprecated AbsoluteLayout class. The follow-on to this one (Part 3) is worth looking at too because it develops further the notion of DropTarget.
(b) Drag-Drop for an Android GridView - a demo app that shows how to use the drag-drop framework for grid views. Even better, it illustrates how to get by without AbsoluteLayout. In this case, the DragLayer and other classes know more about the kind of layouts they are working with.
The demo apps illustrate images and text views being dragged. The underlying code is perfectly general: any view can be dragged. A problem you will face with dragging buttons is making sure that the start of a drag operation will not be confused with the normal click handling that buttons do. Consider using a long click to initiate a drag sequence.

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!)

Android layout render without compiling

I'm new to developing with Android, and the biggest new thing is the way the UI is rendered (relative to other views instead of absolute locations and sizes). As a result, I've been experimenting a lot with layouts, and find myself changing 1 view or even just 1 property of a view, then having to recompile and launch it back into the emulator to see the result. Is there a tool that quickly (or at least quicker) shows what a UI looks like give a layout xml file?
You can look at http://www.droiddraw.org/ but it is not perfect.
You can use Eclipse with Android Development Tools, when opening a layout file you get a preview of what looks like. Besides, ADT provides some nice features for developing and debugging in the Android platform.
When you're in the XML view, simply click the "Layout" tab on the bottom, and you'll be taken to a visual representation of your layout:
Like so:
There are some limitations for sure (e.g. text shadowing, for one, will not be depicted in this view), but it's a good way to get a general idea of how your layout is working.
Versions 2.x and higher of Android Studio render the XML in real-time in the Preview pane of the IDE and it even juxtaposes the XML and outline views side by side.

Categories

Resources