c# - Xamarin.Android 创建和使用自定义控件
问题描述
Xamarin 又是艰难的一天!
所以,今天,我想弄清楚如何在Xamarin.Android
. 我阅读了所有文档,并且都在Xamarin.Forms
. 我想知道为什么对Xamarin.Android
.
无论如何,我遇到了一些关于 SO 的问题并尝试了这个:
测试控制.cs
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)
{
}
}
}
测试控制.xml
<TestApp.CustomControls.Classes.TestControl xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="20dp" android:layout_width="20dp"
android:background="#fff">
在我的activity_main.axml文件中,我有以下内容:
<?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>
即使智能感知能够找到TestApp.CustomControls.Classes.TestControl
,但我在屏幕上看不到任何东西。也许是因为我从未将 xml 文件与类链接?(现在仍然确定 xamarin.android 是如何工作的)。
那么,让自定义控件工作/可见的步骤应该是什么?
解决方案
推荐阅读
- javascript - ReactJS 如何在状态下处理对象的方法?
- sql - 在具有不同 where 子句的子查询中查找百分比
- c# - 在 ASP.Net Core 中为 Web 部署“在目标位置删除其他文件”添加例外?
- reactjs - REDUX-REACT - 调度未定义
- excel - 选择多个列标题,然后删除这些列
- kubernetes - Kubernetes 如何控制复制?
- c# - Digital Persona - 生物特征检查是否带来错误数据(从其他用户那里获取数据)
- c - glUniformMatrix4fv - 无效操作
- java - 在 JavaFX 中添加/删除动画
- python - 无法在 Python 中仅用两个隐藏的神经元解决 XOR 问题