Xamarin android编译的应用程序是空的

时间:2016-12-27 08:27:24

标签: android xamarin.android xamarin.forms

我用VS 2015 Enterprise和Xamarin创建了一个新的android项目,并添加了一些小部件。我每次构建项目并在真正的android 4.4设备上运行时都会得到一个空表单。使用android 4.1编译。

App screenshot 这是main.axml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:gridSpec="1|8|#0093eeff|K:#ee8700ff:16,l:72,l:16,r|S:#83ee00ff:16,0,l:16,56,l:16,0,r"
    android:background="#9a50ea"
    android:minWidth="25px"
    android:minHeight="25px">
<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="10"
            android:background="#9a50ea">
            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="آگهی جدید"
                android:id="@+id/button5"
                android:layout_weight="20"
                android:background="@android:color/transparent"
                android:textColor="@android:color/white"
                android:drawableRight="@drawable/ic_add_white_24dp"
                android:clickable="true" />
            <TextView
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:text="صفحه اصلی"
                android:id="@+id/button6"
                android:layout_weight="35"
                android:background="@android:color/transparent"
                android:textColor="@android:color/white"
                android:gravity="center_vertical"
                fontPath="fonts/Shabnam.ttf" />
            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:id="@+id/imageView"
                android:layout_weight="10"
                android:src="@drawable/logo"
                android:clickable="true" />
        </LinearLayout>
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="10"
            android:gravity="right"
            android:layout_gravity="right"
            android:background="#9a50ea">
            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="چسپ من"
                android:id="@+id/button"
                android:layout_weight="25"
                android:drawableTop="@drawable/ic_person_white_24dp"
                android:background="@android:color/transparent"
                android:textColor="@android:color/white" />
            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="جستجو"
                android:id="@+id/button3"
                android:layout_weight="25"
                android:drawableTop="@drawable/ic_search_white_24dp"
                android:background="@android:color/transparent"
                android:textColor="@android:color/white" />
            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="دسته‌بندی‌ها"
                android:id="@+id/button2"
                android:layout_weight="25"
                android:drawableTop="@drawable/ic_list_white_24dp"
                android:background="@android:color/transparent"
                android:textColor="@android:color/white" />
            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="صفحه اصلی"
                android:id="@+id/button4"
                android:layout_weight="25"
                android:drawableTop="@drawable/ic_home_white_24dp"
                android:background="@android:color/transparent"
                android:textColor="@android:color/white" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

主要活动档案:

using Android.App;
using Android.Widget;
using Android.OS;
using Android.Graphics;
using UK.CO.Chrisjenx.Calligraphy;

namespace Chasp
{
    [Activity(Label = "Chasp", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
        }
    }
}

帮助/ Xamarin /打开日志文件:

Xamarin.VisualStudio.Android.MonoAndroidFlavoredProject Information: 0 : [2016-12-27 11:47:42.8980] designer model checker: DocumentSaved
Xamarin.VisualStudio.Android.MonoAndroidFlavoredProject Information: 0 : [2016-12-27 11:48:01.0096] designer model checker: Build
Xamarin.VisualStudio.ActivationManager Error: 0 : [2016-12-27 11:48:01.1106] Couldn't synchronize/copy Java.Interop.dll
System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at Xamarin.AndroidDesigner.DesignerProject.SynchronizeDirectoryRecursive(String src, String dst)
Xamarin.VisualStudio.ActivationManager Error: 0 : [2016-12-27 11:48:01.1364] Couldn't synchronize/copy mscorlib.dll
System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at Xamarin.AndroidDesigner.DesignerProject.SynchronizeDirectoryRecursive(String src, String dst)
Xamarin.VisualStudio.ActivationManager Error: 0 : [2016-12-27 11:48:01.1454] Couldn't synchronize/copy System.Collections.Concurrent.dll
System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at Xamarin.AndroidDesigner.DesignerProject.SynchronizeDirectoryRecursive(String src, String dst)
Xamarin.VisualStudio.ActivationManager Error: 0 : [2016-12-27 11:48:01.1604] Couldn't synchronize/copy System.Collections.dll
System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at Xamarin.AndroidDesigner.DesignerProject.SynchronizeDirectoryRecursive(String src, String dst)
Xamarin.VisualStudio.ActivationManager Error: 0 : [2016-12-27 11:48:01.1694] Couldn't synchronize/copy System.Core.dll
System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at Xamarin.AndroidDesigner.DesignerProject.SynchronizeDirectoryRecursive(String src, String dst)
Xamarin.VisualStudio.ActivationManager Error: 0 : [2016-12-27 11:48:01.1774] Couldn't synchronize/copy System.Diagnostics.Debug.dll
System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at Xamarin.AndroidDesigner.DesignerProject.SynchronizeDirectoryRecursive(String src, String dst)
Xamarin.VisualStudio.ActivationManager Error: 0 : [2016-12-27 11:48:01.1844] Couldn't synchronize/copy System.dll
System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at Xamarin.AndroidDesigner.DesignerProject.SynchronizeDirectoryRecursive(String src, String dst)
Xamarin.VisualStudio.ActivationManager Error: 0 : [2016-12-27 11:48:01.1934] Couldn't synchronize/copy System.Linq.dll
System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at Xamarin.AndroidDesigner.DesignerProject.SynchronizeDirectoryRecursive(String src, String dst)
Xamarin.VisualStudio.ActivationManager Error: 0 : [2016-12-27 11:48:01.2249] Couldn't synchronize/copy System.Reflection.dll
System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at Xamarin.AndroidDesigner.DesignerProject.SynchronizeDirectoryRecursive(String src, String dst)
Xamarin.VisualStudio.ActivationManager Error: 0 : [2016-12-27 11:48:01.2324] Couldn't synchronize/copy System.Reflection.Extensions.dll
System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at Xamarin.AndroidDesigner.DesignerProject.SynchronizeDirectoryRecursive(String src, String dst)
Xamarin.VisualStudio.ActivationManager Error: 0 : [2016-12-27 11:48:01.2399] Couldn't synchronize/copy System.Runtime.dll
System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at Xamarin.AndroidDesigner.DesignerProject.SynchronizeDirectoryRecursive(String src, String dst)
Xamarin.VisualStudio.ActivationManager Error: 0 : [2016-12-27 11:48:01.2479] Couldn't synchronize/copy System.Runtime.InteropServices.dll
System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at Xamarin.AndroidDesigner.DesignerProject.SynchronizeDirectoryRecursive(String src, String dst)
Xamarin.VisualStudio.ActivationManager Error: 0 : [2016-12-27 11:48:01.2579] Couldn't synchronize/copy System.Threading.dll
System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at Xamarin.AndroidDesigner.DesignerProject.SynchronizeDirectoryRecursive(String src, String dst)

2 个答案:

答案 0 :(得分:1)

您仍然需要将布局设置为以下内容:

[Activity(Label = "Chasp", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView (Resource.Layout.Main);
    }
}

这将加载您的axml文件并将其设置为内容。

默认情况下没有这样做的原因可能是因为有多种方法可以构建您的UI。您也可以在代码中定义它,也许这个默认代码在另一个项目模板中。无论如何,你可能不会很快忘记这一点!

答案 1 :(得分:0)

您必须在

后的OnCreate方法中将布局设置为内容
base.OnCreate(bundle);
SetContentView (Resource.Layout.Main);