绘制自定义视图并调整其大小以适合屏幕尺寸

时间:2018-11-05 07:57:53

标签: java android

我正在使用Android Studio创建读书应用程序,但遇到了一些问题。
请参阅所附图片。

  1. 我插入了图像并设置了合适的屏幕
  2. 我创建了“自定义”视图并绘制drawRect。

我有矩形X和Y位置,但是很大。
我希望所有设备都适合屏幕。

有人可以帮我吗?
谢谢。

这是自定义视图代码

 @Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Rect rectangle;
    Paint paint = new Paint();
    paint.setColor(Color.GRAY);

    File DBFile = new File(getContext().getExternalFilesDir(null), "Rectangles.db");
    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(DBFile, null);
    Cursor cur = db.rawQuery("SELECT * FROM ExportLine WHERE PageNo = 1", null);

    cur.moveToFirst();

    while(!cur.isAfterLast()) {
        int lineX = cur.getInt(cur.getColumnIndex("X"));
        int lineY = cur.getInt(cur.getColumnIndex("Y"));

        int lineMaxX = cur.getInt(cur.getColumnIndex("XMax"));
        int lineMaxY = cur.getInt(cur.getColumnIndex("YMax"));

        rectangle = new Rect(lineX , lineY, lineMaxX, lineMaxY);
        canvas.drawRect(rectangle, paint);

        cur.moveToNext();
    }
}

This is i Created

I want to like this

我创建的第一张图片
我想要最后一张图片

我所有坐标

0 个答案:

没有答案