Sco*_*ght 6 c# layout android xamarin.android 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));
};
Run Code Online (Sandbox Code Playgroud)
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);
}
}
Run Code Online (Sandbox Code Playgroud)
有没有人知道为什么没有显示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>
Run Code Online (Sandbox Code Playgroud)
Xamarin 中的某个地方似乎存在错误。当我来回重命名 .axml 文件并尝试使用 value\strings.xml 中的字符串(有时给它们提供与 .axml 文件相同的名称)时,我也遇到了空白屏幕(操作栏除外)。虽然不确定字符串是否与它有关,但我记得在编译时遇到了某种错误。
不管怎样,我的解决方案是
之后我进行了一次测试,一切又恢复正常了。
| 归档时间: |
|
| 查看次数: |
6542 次 |
| 最近记录: |