开发者

how can i use self-defined view in the res/layout/main.xml file

The problem is proposed because I want to edit the position, color, and oth开发者_StackOverflow中文版er display properties in the "what you see is what you get" mode; therefore, add some specific behavior in its onDraw(Canvas) function. So, i want to rewrite the view class, currently use own-defined class in res/layout/main.xml is unsupported.

Anyone knows some solution?


Create your own class that extends View and override onDraw method. Than use it in xml with the fully qualified name of the class. Something like this

....
<your.package.MyView android:id="@+id/my_id" ..../>
....

Then in your code get a reference to it like this

MyView mv = (MyView)findViewById(R.id.my_id);

Here is good example of the above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜