在XML中引用自定义视图不能同时使用两种记录的方法吗? [英] Referencing custom view in XML doesn´t work both documented ways?

查看:59
本文介绍了在XML中引用自定义视图不能同时使用两种记录的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<com.test.www.BrushPreview android:id="@+id/brushview"
    android:layout_width="100dip" android:layout_height="100dip"
    android:layout_gravity="center" />

而不是:

<View class="com.test.www.BrushPreview" android:id="@+id/brushview"
    android:layout_width="100dip" android:layout_height="100dip"
    android:layout_gravity="center" />

按照文档 http://developer.android.com/guide/topics/ui/custom-components.html#modifying 它应该同时起作用!我在做什么错了?

Following the documentation http://developer.android.com/guide/topics/ui/custom-components.html#modifying it should work both ways! What am I doing wrong?

小写视图似乎有效!我以为我已经尝试过了...谢谢! 而且,在视图类中使用此构造函数非常重要:

edit: lowercase view seems to work! i thought i tried that already...thanks! and furthermore, it´s very important to use this constructor in the view class:

public BrushPreview(Context context, AttributeSet attrs) 

否则它将不会被呼叫.

推荐答案

对于自定义布局,应在xml中使用小写字母view:

You should use lowercase view in the xml for your custom layout:

<view class="com.test.www.BrushPreview" android:id="@+id/brushview"
    android:layout_width="100dip" android:layout_height="100dip"
    android:layout_gravity="center" />

(也根据您的链接),而且应该可以.

(according to your link too), and it should work.

否则,它将尝试创建一个android.view.View实例.

Otherwise it tries to create a android.view.View instance.

这篇关于在XML中引用自定义视图不能同时使用两种记录的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆