2013-01-10 4 views
1

J'ai une classe qui étend le HorizontalScrollView. Mais je ne sais pas comment je peux l'utiliser dans le xml. Si j'utiliser mon nom de classe comme balise xml, je suis une erreur: Classe d'erreur de gonflage MyClassMonodroid: utilisation de la classe de vue étendue en xml

Mon code:

public class ToothScroller : HorizontalScrollView 
{ 

    private GestureDetector mGestureDetector; 

    public ToothScroller(Context context) : base(context) 
    { 
    } 

    public ToothScroller(Context context, IAttributeSet attrs) : base(context, attrs) 
    { 

     SetFadingEdgeLength(0); 
    } 

    public ToothScroller(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) 
    { 
    } 

    public ToothScroller(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) 
    { 
    } 


    public override bool OnInterceptTouchEvent (Android.Views.MotionEvent ev) 
    { 
     Console.WriteLine(this.ScrollX); 

     return base.OnInterceptTouchEvent (ev); 
    } 

} 

Et mon xml (AXML) Code:

<MyClass 
     android:id="@+id/scrollMyClass" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@+id/imageSomething" 
     android:fillViewport="true" 
     android:background="@drawable/pusherbg"> 
     <RelativeLayout 
      android:id="@+id/layoutSomething" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 
    </MyClass> 

Nous vous remercions de Aidez-moi.

Répondre

0

Merci pour l'aide, cela fonctionne maintenant avec le code suivant. Packagename était un peu déroutant, parce que dans Monodroid, que j'utilise, c'est l'espace de noms que je dois utiliser, pas le nom de fichier.

<MyNamespace.MyClass 
    android:id="@+id/scrollMyClass" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/imageSomething" 
    android:fillViewport="true" 
    android:background="@drawable/pusherbg"> 
    <RelativeLayout 
     android:id="@+id/layoutSomething" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 
</MyNamespace.MyClass> 
2

Remplacer cette

<MyClass 
    android:id="@+id/scrollMyClass" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/imageSomething" 
    android:fillViewport="true" 
    android:background="@drawable/pusherbg"> 

avec

<YourPackage.YourClass 
    android:id="@+id/scrollMyClass" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/imageSomething" 
    android:fillViewport="true" 
    android:background="@drawable/pusherbg"> 
+0

Dans cette seconde que je voulais ajouter: J'ai aussi essayé MyPackage.xy.MyClass avec la même erreur – anguish

+1

Il doit être en minuscule. Je le fais ici dans ce projet: https://github.com/Cheesebaron/MonoDroid.ActionBar/blob/master/MonoDroid.ActionBar/Resources/Layout/Main.axml pour la vue: https://github.com/Cheesebaron /MonoDroid.ActionBar/blob/master/MonoDroid.ActionBar/ActionBar/ActionBar.cs – Cheesebaron

1

Modifier votre mise en page XML à ceci:

<com.username.package.MyClass 
    android:id="@+id/scrollMyClass" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/imageSomething" 
    android:fillViewport="true" 
    android:background="@drawable/pusherbg"> 
    <RelativeLayout 
     android:id="@+id/layoutSomething" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 
</com.username.package.MyClass> 

Voici une bonne ressource avec plus de détails directement à partir de Google qui va probablement pour avoir beaucoup plus d'informations sur la façon de créer une vue personnalisée: http://developer.android.com/guide/topics/ui/custom-components.html

Questions connexes