我第一次运行与Xamarin的android项目。
我想转换代码xml到xamarin或Java
且在完成事件后可见
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".BlankFragment2">
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello_blank_fragment" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="next"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="pre"/>
</LinearLayout>
欢迎来到Stack。
您可以使用“转换到Java”的链接
将XML转换为Java
和xamarin:测试一下
LinearLayout layout = FindViewById<LinearLayout>(Resource.Id.parent);
LayoutParams lp = new LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent);
button1 = new Button(this);
button1.Text = "click1";
layout.AddView(button1, lp);
button2 = new Button(this);
button2.Text = "click2";
layout.AddView(button2, lp);
TextView text = new TextView(this);
text.Text = "text";
layout.AddView(text, lp);
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".BlankFragment2">
</LinearLayout>