2013-03-16 64 views
5

我正在使用Xamarin開發應用程序。當通過Xamarin中的新活動加載時,佈局不顯示內容

我有三個活動,DiallerActivityContactsActivitySplashActivity - 和兩個.axml佈局,Main.axml和Contacts.axml

SplashActivity是第一加載的,其顯示一個濺射屏幕打開應用程序,當它完成時,它加載DiallerActivity它顯示我的Main.axml佈局 - 這工作正常。

裏面我Main.axml佈局我點擊它加載時的ContactsActivity然後應該加載Contacts.axml這只是內部有3個按鈕和一個標籤..它們都沒有被編程的按鈕做任何事。

問題是,當單擊按鈕時,顯示將變爲空白屏幕,仍然在屏幕頂部顯示安卓欄..它只是不會顯示.axml文件中的任何內容。

我需要Contacts.axml佈局當活動運行時顯示..我希望我已經明確這一點。我目前的代碼如下。

代碼DiallerActivity

protected override void OnCreate (Bundle bundle) 
    { 
     base.OnCreate (bundle); 

     // Set our view from the "main" layout resource 
     SetContentView (Resource.Layout.Main); 

Button btnAcceptClick = FindViewById<Button> (Resource.Id.btnAccept); 

btnAcceptClick.Click += delegate { 
      StartActivity (typeof(VoWiFiApplicationFinal.ContactsActivity)); 
     }; 

代碼ContactsActivity

public class ContactsActivity : Activity 
{ 
    protected override void OnCreate (Bundle bundle) 
    { 
     base.OnCreate (bundle); 

     // setting the contacts.axml as the view 
     SetContentView (Resource.Layout.Contacts); 
    } 
} 

有沒有人有,爲什麼不顯示任何Contacts.axml想法?如果你需要我提供任何更多的信息只是說,我會把它..我正在使用C#作爲我的語言,所以我更喜歡相關的幫助,如果它甚至適用於問題心神。謝謝閱讀。

Contacts.xaml代碼

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical"> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:id="@+id/toptest" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+/label1" 
     android:text="testlabel" /> 
</LinearLayout> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:id="@+id/testagain" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" /> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:id="@+id/menuBar" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <Button 
     android:layout_width="fill_parent" 
     android:text="ACCEPT" 
     android:id="@+id/btnAccep" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 
    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/btnDeclin" 
     android:layout_weight="1" 
     android:text="DECLINE" /> 
    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/btntes" 
     android:layout_weight="1" 
     android:text="TEST" /> 
</LinearLayout> 
</LinearLayout> 
+0

你能發佈你的聯繫人佈局嗎?如果您從一開始就使用(例如撥號器活動中的示例,它的工作原理是什麼?) – Luksprog 2013-03-16 20:29:52

+0

我已經從聯繫人佈局中附加了代碼..沒有它沒有加載,並且如果我更改了應用程序,我甚至遇到了一些問題在撥號器應用程序的開始。 – 2013-03-16 22:02:12

+1

我得到完全相同的東西;我的第二個活動的OnCreate正在觸發,並且對SetContentView的調用不會引發任何異常,但即使我在.axml中有(顯然是有效的)標記,我也會看到一個空白顯示? – sh1rts 2014-04-24 10:02:51

回答

0

似乎是Xamarin一個錯誤的地方。當我重新命名.axml文件並在values \ strings.xml中嘗試字符串時,我也得到了一個空白屏幕(除了操作欄),有時會給它們與.axml文件相同的名稱。不知道字符串是否與它有任何關係,但我記得在編譯時出現某種錯誤。

反正對我來說,解決辦法是

  1. 備份.axml文件的內容,並徹底刪除該文件。
  2. 使用不同於原始名稱的另一個名稱創建一個新的.axml文件。
  3. 將備份的內容粘貼到新文件中。
  4. 將新文件重新命名爲舊名稱。

之後,我做了一個測試運行,一切都重新運行。

相關問題