我正在使用Xamarin開發應用程序。當通過Xamarin中的新活動加載時,佈局不顯示內容
我有三個活動,DiallerActivity,ContactsActivity和SplashActivity - 和兩個.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>
你能發佈你的聯繫人佈局嗎?如果您從一開始就使用(例如撥號器活動中的示例,它的工作原理是什麼?) – Luksprog 2013-03-16 20:29:52
我已經從聯繫人佈局中附加了代碼..沒有它沒有加載,並且如果我更改了應用程序,我甚至遇到了一些問題在撥號器應用程序的開始。 – 2013-03-16 22:02:12
我得到完全相同的東西;我的第二個活動的OnCreate正在觸發,並且對SetContentView的調用不會引發任何異常,但即使我在.axml中有(顯然是有效的)標記,我也會看到一個空白顯示? – sh1rts 2014-04-24 10:02:51