Gridview,允许背景画布在视图外部绘制

FIG*_*742 4 android gridview canvas

我正在为Android开发一个应用程序,一个小的记事本应用程序.在我的应用程序中,我使用Gridview创建一个2*X大小的网格,并在每个单元格中我有一个LinearLayout调用AbstractNote,其任务是显示应用程序中每个保存注释的预览.

我的AbstractNote有一个背景图像,有点旋转,以显示预览更精美.但我的问题是,当我旋转图像时,其中一些落在AbstractNote区域之外,我找不到一个很好的方法来显示它.

我尝试使用View.setAnimation(...)它并且它有效,但给我粗糙的图像和文本,我已经尝试创建一个自定义Drawable(设置为AbstractNote.setBackgroundDrawable(...)),给我流畅的图像,但不显示完整的图像.

请注意,我的目标android是2.1,我不使用 View.setRotation(...)

使用a View.setAnimation执行此操作但获得粗糙的图像和文本

使用自定义drawable,但不能在单元格外部绘制.

如果有人知道如何修复它,通过修复尝试1中的粗糙图像和文本或如何在尝试2中在单元格外绘制图像,我将非常感激.

FIG*_*742 5

我终于找到了问题的解决方案,解决方案不是很好但是工作,想法是绘制单元格项目直接在GridView上绘制背景而不是GridView childen/item

我创建一个新的GridView:

public class NoteGridView extends GridView {
@Override
protected void dispatchDraw(Canvas canvas) {
    final int count = getChildCount();
    if (count > 0) {
        for (int i = 0; i < this.getChildCount(); i++) {
            // For each of my childen draw it backgrund that allow to draw bg that is bigger then cell.
            View childAt = this.getChildAt(i);
            if (childAt instanceof AbstractNote) {
                final AbstractNote note = (AbstractNote) childAt;
                // Set the zero point to the start of the childen, then call the childen draw methods.
                canvas.save();
                canvas.translate(childAt.getLeft(), childAt.getTop());
                note.drawBackground(canvas);
                canvas.restore();
            }
        }
    }
    super.dispatchDraw(canvas);
}
}
Run Code Online (Sandbox Code Playgroud)

在我的孩子们中AbstractNote我添加了方法drawBackground,这个背景我在我的绘制中AbstractNote现在是在GridView画布上绘制的,它比我在的小画布大得多AbstractNote