开发者

Android: draw on a view inside an inflated xml (another view)

I have a small xml file called 'xmlview.xml' which is something like:

<tablelayout>
   <tablerow>
      <view id="view1" />

I created a class which ext开发者_开发百科ends 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 ??


Seems to me maybe you should try something like this:

<TableLayout>
   <TableRow>
     <com.yourdomain.yourproject.ViewClassName>

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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜