2016-12-27 103 views
0

我用VS 2015 Enterprise和Xamarin製作了一個新的android項目,並添加了一些小部件。每次構建項目並在真正的Android 4.4設備上運行時,我都會得到一個空表單。使用android 4.1進行編譯。Xamarin android編譯應用程序爲空

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) 
+1

設置佈局在onCreate方法的內容我覺得你還是需要設置的佈局像'的setContentView(Resource.Layout.Main)的內容;你'基地後'。 OnCreate(捆綁);' –

+0

OMG!我花了兩個小時,我沒有意識到這一點!謝謝。請回答問題,以便我能夠接受它。爲什麼xamarin不會爲新項目添加它? – l3est

回答

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文件並將其設置爲內容。

默認情況下沒有這樣做的原因可能是因爲有多種方式來構建您的用戶界面。你也可以在代碼中定義它,也許這個默認代碼在另一個項目模板中。無論如何,你可能不會很快忘記這一點!

0

你有後

base.OnCreate(bundle); 
SetContentView (Resource.Layout.Main); 
相關問題