Android:在膨胀的 xml 内的视图上绘制(另一个视图)
我有一个名为“xmlview.xml”的小 xml 文件,类似于:
<tablelayout>
<tablerow>
<view id="view1" />
我创建了一个扩展视图的类,然后我膨胀了该 xml 文件,现在我有了一个由于膨胀而获得的视图。
xmlView = layoutInflater.inflate(R.layout.xmlview, this);
我想知道是否有一种方法可以在视图“xmlview”内的视图“view1”上绘制
我尝试过类似的操作:
View view1 = (View)xmlview.findById(R.Id.view1);
然后我尝试在覆盖的 onDraw 中绘制 view1 但没有任何效果,
有什么想法吗?
I have a small xml file called 'xmlview.xml' which is something like:
<tablelayout>
<tablerow>
<view id="view1" />
I created a class which extends view, and I inflated that xml file and now i have a view obtained due to inflation.
xmlView = layoutInflater.inflate(R.layout.xmlview, this);
I am wondering is there a way to draw on the view 'view1' inside the view 'xmlview'
I tried something like:
View view1 = (View)xmlview.findById(R.Id.view1);
and then I tried in the overriden onDraw to draw on view1 but nothing worked,
any ideas ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,也许你应该尝试这样的事情:
然后你可以创建一个扩展 View 的类 ViewClassName ,并在该类上重写 onDraw 方法。此处详细解释: http://developer.android.com/ Guide/topics/ui/custom-components.html。您可以直接进入主题修改现有视图类型
看看,如果这样做的唯一原因是尝试操纵视图的绘制,则不需要膨胀视图。如果这是唯一的原因,你真的不应该这样做。
希望我有帮助
Seems to me maybe you should try something like this:
Then you can create a class ViewClassName that extends View and, on that class, override the onDraw method. This is explained in detail here: http://developer.android.com/guide/topics/ui/custom-components.html. You can go directly the topic Modifying an Existing View Type
See, you don't need to inflate the view if the only reason to do this is to try and manipulate the view's drawing. And if it is the only reason, you really shouldn't.
hope I helped
我不确定“在视图上绘制”到底是什么意思,但听起来您应该研究 画布.您不应随意重写
onDraw
方法,这会导致您的小部件出现在屏幕上。I'm not sure what exactly you mean by "draw on the view", but it sounds like you should be looking into the Canvas. You should not arbitrarily override the
onDraw
method, this is what causes your widgets to appear on the screen.