0
因此,iv創建了擴展視圖的類。這裏是我的代碼:onDraw()方法不能正常工作
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (!mTablesList.isEmpty()) {
drawTables(canvas);
}
}
private void drawTables(Canvas canvas) {
for (Table table : mTablesList) {
canvas.drawRect(mWidht * table.getLeft()/100, mHeight * table.getTop()/100, mWidht * table.getRight()/100, mHeight * table.getBottom()/100, m1Paint);
saveInfo(table, mWidht * table.getLeft()/100, mHeight * table.getTop()/100, mWidht * table.getRight()/100, mHeight * table.getBottom()/100);
}
}
private void saveInfo(Table table, int left, int top, int right, int bottom) {
Rect rect = new Rect();
rect.set(left, top, right, bottom);
table.setRect(rect);
mTablesListTouch.add(table);
}
現在,我有2個需要繪製的對象。第一個對象總是被繪製,但第二個對象不是。當我的第二個對象座標是left和top == left和top時,它不顯示,當對象繪製在繪製的對象1下方時,它顯示。有人可以給我一個解決方案嗎?
private void makeTables() {
Table table = new Table();
table.setLeft(20);
table.setTop(7);
table.setRight(40);
table.setBottom(20);
table.setAvailable(true);
table.setID(1);
listOfTables.add(table);
Table table1 = new Table();
table1.setLeft(20);
table1.setTop(70);
table1.setRight(60);
table1.setBottom(20);
table1.setAvailable(true);
table1.setID(2);
listOfTables.add(table1);
mTables.setTables(listOfTables);
}
settin mTables。
行,所以,這是setTables()方法:
public void setTables(List<Table> tables) {
mTablesList = tables;
mPaint.setColor(getResources().getColor(android.R.color.black));
invalidate();
}
後,它callse onMeasure()和的onDraw()
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
final int height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);
mWidht = width;
mHeight = height;
setMeasuredDimension(mWidht, mHeight);
}
帶上一個代碼,你正在填寫mTablesList – AterLux
它是在裏面的活動,從那裏調用setTables()方法 –
好的。現在,裏面有什麼「setTables()」?如果您從創建過程中獲得「表格」的完整生命週期,那就更好了。 – AterLux