Gridview,允许背景画布在视图外绘制 [英] Gridview, allow background canvas to draw outside of view

查看:125
本文介绍了Gridview,允许背景画布在视图外绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我有什么我的AbstractNote有一个背景图像,有点旋转为显示
的预览更美观。但我的问题是,当我旋转图像一些它落在AbstractNote区域之外,我找不到一个很好的方式来显示这个。



我试过使用 View.setAnimation(...),它可以工作,但给我坚固的图像和文本,
和我已经尝试定制一个自定义Drawable AbstractNote.setBackgroundDrawable(...)),它给我平滑的图像,但不显示完整的图像。



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



code> View.setAnimation 这样做,但得到粗糙的图像和文本





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





如果有人知道如何解决它,通过修复坚固的图像和文本在尝试1或
如何绘制图像外单元格尝试2,我会非常感激。



我创建一个新的GridView为:

  public class NoteGridView extends GridView {
@Override
protected void dispatchDraw(Canvas canvas){
final int count = getChildCount();
if(count> 0){
for(int i = 0; i //对我的每个孩子绘制允许绘制比细胞更大的bg。
查看childAt = this.getChildAt(i);
if(childAt instanceof AbstractNote){
final AbstractNote note =(AbstractNote)childAt;
//将零点设置为childen的开始,然后调用childen绘制方法。
canvas.save();
canvas.translate(childAt.getLeft(),childAt.getTop());
note.drawBackground(canvas);
canvas.restore();
}
}
}
super.dispatchDraw(canvas);
}
}

在我的孩子 AbstractNote 我添加方法 drawBackground ,这做背景我在 AbstractNote 现在画在GridView画布上,比我在 AbstractNote


I'm developing an app for Android, a small notepad app. In my app I use a Gridview for create a grid of 2*X size and in each cell I has a LinearLayout call AbstractNote that has in task to show a preview of each save note in the app.

I what my AbstractNote to has a background image that is some bit rotate for show the preview more beautifully. But my problems is while i rotate the image some of it falls outside of the AbstractNote Area, and I'not find a good way to show this to.

I has try to use View.setAnimation(...) and it works but give me rugged image and text, and I has try to crate a custom Drawable (set as AbstractNote.setBackgroundDrawable(...)) that give me smooth image but not show the full image.

Do note, My target android is 2.1 and I not use View.setRotation(...)

Use a View.setAnimation for do this but get rugged image and text

Use custom drawable, but can't paint outside of the cell.

If somebody know how to fix it, by fix the rugged image and text in attempted 1 or how to draw image outside the cell in attempted 2, I will be very grateful.

解决方案

I has finally find a solution on the problem, the solution is not very good but work, the idea was to draw the cells item directly draw the background on the GridView and not the GridView childen/item

I Create a new GridView as:

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);
}
}

And in my children AbstractNote I add the method drawBackground, this do that background I what to draw in my AbstractNote is now draw on the GridView canvas that is much bigger then the small canvas I has in AbstractNote

这篇关于Gridview,允许背景画布在视图外绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆