2016-08-12 31 views
0

我有一個名爲SquareImageView的自定義視圖,我想在我的xml文件中使用它。但我的XML似乎無法解決它。爲什麼?我試着給它以小寫完全合格的命名空間Xamarin沒有看到我的自定義視圖

XML:

<?xml version="1.0" encoding="utf-8"?> 

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <pokemonmobileclient.SquareImageView 
     android:id="@+id/picture" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="centerCrop" /> 
    <TextView 
     android:id="@+id/text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     android:paddingTop="15dp" 
     android:paddingBottom="15dp" 
     android:layout_gravity="bottom" 
     android:textColor="@android:color/white" 
     android:background="#55000000" 
     /> 
</FrameLayout> 

類:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

using Android.App; 
using Android.Content; 
using Android.OS; 
using Android.Runtime; 
using Android.Text.Style; 
using Android.Util; 
using Android.Views; 
using Android.Widget; 

namespace PokemonMobileClient 
{ 

    public class SquareImageView : ImageView 
    { 
     public SquareImageView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) 
     { 
     } 

     public SquareImageView(Context context) : base(context) 
     { 

     } 

     public SquareImageView(Context context, IAttributeSet attrs) : base(context, attrs) 
     { 
     } 

     public SquareImageView(Context context, IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr) 
     { 
     } 

     public SquareImageView(Context context, IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes) 
     { 

     } 

     protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) 
     { 
      base.OnMeasure(widthMeasureSpec, heightMeasureSpec); 
      SetMeasuredDimension(this.MeasuredWidth, this.MeasuredHeight); 
     } 
    } 
} 

<pokemonmobileclient.SquareImageView有下劃線說invalid child element pokemonmobileclient.SquareImageView

我爲什麼不能引用它?

謝謝

回答

1

這是一個智能感知警告,如果有的話。這段代碼仍然可以正常工作。我相信這只是intellisense端的一個錯誤,因爲當您創建一個擴展其中一個子元素的自定義視圖時,它無法找到這些子元素之一。

enter image description here

正如你可以看到這個代碼工作得很好:

enter image description here

相關問題