简体   繁体   English

让Xamarin Android Designer与Toolbox一起使用

[英]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. 这个问题是关于支持拖放功能的Xamarin Android,而不是Xamarin Forms。

When using the Xamarin Android Designer in Visual Studio I am only allowed to drag in one control from the toolbox. 在Visual Studio中使用Xamarin Android Designer时,我只能从工具箱中拖入一个控件。 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: 重现问题的步骤:

  1. Create a new Xamarin Android App project in Visual Studio. 在Visual Studio中创建一个新的Xamarin Android App项目。
  2. Navigate to the "Resources/layout/activity_main.axml". 导航到“Resources / layout / activity_main.axml”。
  3. 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. 我已经在网上找到了一个解决方案,包括Xamarin社区论坛和Visual Studio开发者社区,但只发现了相同或类似问题的帖子,没有对我有用的解决方案。 How can I solve this? 我怎么解决这个问题?

RelativeLayout in Xaml doesn't allow drag&droping more than 1 control by design. Xaml中的RelativeLayout不允许按设计拖放多于1个控件。

RelativeLayout is a ViewGroup that displays child View elements in relative positions. RelativeLayout是一个ViewGroup ,它以相对位置显示子View元素。 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). 视图的位置可以指定为相对于同级元素(例如,给定元素的左侧或下方)或相对于RelativeLayout区域的位置(例如与中心的底部,左侧对齐)。

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. 您可以根据原始拖动控件从Xaml定位其他控件。 You can drag&drop controls from toolbox directly to Xml code and it allows you to edit further the control from Properties box. 您可以将控件从工具箱直接拖放到Xml代码,它允许您从“属性”框中进一步编辑控件。

Also, https://developer.android.com/guide/topics/ui/layout/relative officially recommends to use ConstraintLayout instead. 此外, https://developer.android.com/guide/topics/ui/layout/relative正式建议使用ConstraintLayout

If you insists to use RelativeLayout , you will have to code the interface in Xaml. 如果您坚持使用RelativeLayout ,则必须在Xaml中对接口进行编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM