Hi,
I'm writing an app where I'd like to draw to a Canvas inside each
element of a ListView.
To do this I have created the ListView with a custom Adaptor,
overriding the getView function to inflate a new View as shown below:
@Override
public View getView(int position, View convertView, ViewGroup
parent)
{
//Change row view to include textview at the top
//followed by canvas
Row row = elements.get(position);
RowCanvas rowCanvas = (RowCanvas) convertView;
if (rowCanvas == null) {
// inflate a new view
rowCanvas = (RowCanvas)
LayoutInflater.from(context).inflate(R.layout.row,
parent, false);
}
return rowCanvas;
}
...where the RowCanvas class which extends View is as follows:
public RowCanvas(Context context, AttributeSet attrs) {
super(context, attrs);
paint = new Paint();
paint.setColor(Color.WHITE);
}
/*@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
setMeasuredDimension(400, 40);
}*/
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawText("Testing this is working...", 25, 25, paint);
//canvas.drawRect( /* e.g. from 10% across the screen to 90%
across
*/ );
}
As you can see, at the moment I'm unsure how I would go about drawing
something in the Canvas so that it fills a certain percentage of the
width of the screen, and how to correctly set the dimensions of the
RowCanvas view, as at the moment I'm just arbitrarily setting them.
What's the best way to go about this?
Thanks for any help in advance.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en