与Xamarin一起度过艰难的一天!
因此,今天,我试图弄清楚如何在BBQ Pork & Onion $8.50
Apricot Chicken $13.50
Ham & Cheese $8.50
Mr. Wedge $13.50
Hawaiian $8.50
BBQ Meatlovers $13.50
Pepperoni $8.50
Beef & Onion $8.50
Godfather $13.50
Cheesy Garlic $8.50
Simply Cheese $8.50
Cranberry & Chicken $13.50
中创建和使用自定义控件。我阅读了所有文档,所有文档都在Xamarin.Android
上。我不知道为什么对Xamarin.Forms
的支持如此之少。
无论如何,我在SO上遇到了几个问题,并尝试了以下方法:
TestControl.cs
Xamarin.Android
TestControl.xml
namespace TestApp.CustomControls.Classes
{
public class TestControl : ViewGroup
{
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
throw new NotImplementedException();
}
public TestControl(Context context, IAttributeSet attrs)
: base(context, attrs)
{
}
}
}
在我的 activity_main.axml 文件中,我具有以下内容:
<TestApp.CustomControls.Classes.TestControl xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="20dp" android:layout_width="20dp"
android:background="#fff">
尽管intellisense能够找到<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="50dp"
android:layout_weight="50dp">
<TestApp.CustomControls.Classes.TestControl android:layout_height="50dp"
android:layout_weight="50dp"/>
</RelativeLayout>
,但我在屏幕上看不到任何东西。也许是因为我从未将xml文件与该类链接?(现在仍然确定xamarin.android的工作方式)。
那么,如何使自定义控件在视图中正常工作/可见?