Android MvxFrameLayout派生类不';不要画小孩

Android MvxFrameLayout派生类不';不要画小孩,android,mvvmcross,Android,Mvvmcross,我创建了一个测试MvxFrameLayout派生类,我想在该类中绘制一个大小为24x24的0,0的子类: public class MyCustomLayout : MvxFrameLayout { public MyCustomLayout(Context context, IAttributeSet attrs) : base(context, attrs) { } public MyCustomLayout(

我创建了一个测试MvxFrameLayout派生类,我想在该类中绘制一个大小为24x24的0,0的子类:

    public class MyCustomLayout : MvxFrameLayout
    {
        public MyCustomLayout(Context context, IAttributeSet attrs) : base(context, attrs)
        {
        }

        public MyCustomLayout(Context context, IAttributeSet attrs, IMvxAdapterWithChangedEvent adapter) : base(context, attrs)
        {
        }

        protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
        {
            if (!changed)
            {
                return;
            }
            for (int i = 0; i < this.ChildCount; ++i)
            {
                var child = this.GetChildAt(i);
                child.Layout(0, 0, 24, 24);
            }
        }
    }
hotspot.xml是一个图像视图,图像(circle.png)为24x24:

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/circle" />

问题是没有绘制圆图像

如果在hotspot.xml中,我将android:layout\u width=“fill\u parent”和
android:layout\u height=“fill\u parent
更改为
wrap\u content
,则会绘制图像,但不正确。 该图像被画成两半。它看起来像是将图像缩放到其大小的两倍,并将其裁剪成两半(可能是由于“child.Layout(0,0,24,24))


我不确定发生了什么。我看到
OnLayout
中的
子项
cirrial.mvvmcross.binding.droid.views.MvxListItemView
类型,而不是我所期望的“ImageView”。也许这与此有关。

MvxFrameLayout
通过对子项
mvxlistitemvxlvie>进行充气来工作w
用于每个子级。
MvxListItemView
本身继承自
FrameLayout
,并具有默认布局参数

根据文档--这意味着每个子框架布局的大小应为:

FrameLayout的大小是其最大子级(加上填充)的大小,无论是否可见(如果FrameLayout的父级允许)

既然您在这里为
ImageView
内部子视图指定了
fill\u parent
,那么我猜这就是导致内部视图大小为零的原因

为了给您的子帧一些大小,最好在内部子XML中直接给它们
ImageView
大小,而不是请求
fill\u parent


如果您确实希望直接返回
ImageView
并将其用作子级,而不使用中间
MvxListItemView
,那么在最新的MvvmCross源代码中,我相信您可以:

  • ImageView
    继承类
    MyImageView
    ,并添加
    IMvxListItemView
    实现
  • 使用自定义适配器,该适配器在重写的
    CreateBindableView
    中创建并返回
    MyImageView

我为图像指定了宽度和高度,但仍然无法正常工作。我会将您的评论标记为回答:)我不确定如何进行适配器工作,我很忙。我将进行快速自定义视图
public class FirstViewModel : MvxViewModel
{
    public string[] Hotspots { get; private set; }

    public FirstViewModel()
    {
        this.Hotspots = new string[] { "A" };
    }
}
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/circle" />