Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

Export a layout from Visual Studio to Android Studio with XML

I am trying to export the Visual Studio layout to XML and then import it into Android Studio, but I have a problem. The code at the moment generates the first line of the XML that Android Studio has.

<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:layout_width = "match_parent" android:layout_height = "match_parent" />

But when exporting in XML the "android:" disappear leaving only

<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" layout_width = "match_parent" layout_height = "match_parent" />

What can be done so that it doesn't ignore the "android:"?

To do the XML I use the following;

using System.Xml;
using System.Xml.Serialization;
        ...
                XmlDocument xmlDoc = new XmlDocument();
                XmlNode rootNode;
                string filename = "export.xml";
                if (System.IO.File.Exists(filename))
                {
                    xmlDoc.Load(filename);
                    rootNode = xmlDoc.SelectSingleNode("LinearLayout");
                }
                else
                {
                    rootNode = xmlDoc.CreateElement("LinearLayout");
                    xmlDoc.AppendChild(rootNode);
                    XmlAttribute link = xmlDoc.CreateAttribute("xmlns:android");
                    link.Value = "http://schemas.android.com/apk/res/android";
                    rootNode.Attributes.Append(link);
    
                    XmlAttribute widthRoot = xmlDoc.CreateAttribute("android:layout_width");
                    widthRoot.Value = "match_parent";
                    rootNode.Attributes.Append(widthRoot);
    
                    XmlAttribute heightRoot = xmlDoc.CreateAttribute("android:layout_height");
                    heightRoot.Value = "match_parent";
                    rootNode.Attributes.Append(heightRoot);
                }
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Encoding = new UTF8Encoding(false); // Falso = no escribir BOM
                settings.Indent = true;
                XmlWriter writer = XmlTextWriter.Create(filename, settings);
                xmlDoc.Save(writer);
question from:https://stackoverflow.com/questions/65860990/export-a-layout-from-visual-studio-to-android-studio-with-xml

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...