GridView控件,让背景画布视图之外画 [英] Gridview, allow background canvas to draw outside of view

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

问题描述

我在开发Android,一个小记事本程序的应用程序。
在我的应用我使用的GridView用于创建2 * X尺寸的网格,每个单元格
我有一个的LinearLayout通话AbstractNote有任务中表现出的每节省preVIEW
请注意在应用程序。

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.

我什么我AbstractNote到了一个背景图片是表现出一定的旋转位
在preVIEW更加绚丽。但我的问题是当我转动它的一些属于AbstractNote区外的图片,并I'not找到一个很好的方式展现这

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.

我已经尝试使用 View.setAnimation(...)和它的作品,但让我坚固的图片和文字,
我有尝试箱子自定义绘制对象(设置为 AbstractNote.setBackgroundDrawable(...)),它给我的平滑图像而不是表现完整的图像。

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.

待办事项,我的目标是Android的2.1和我没有使用 View.setRotation(...)

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

使用 View.setAnimation 为做到这一点,但得到坚固的图片和文字

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

使用自定义绘制,但无法描绘细胞外。

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

如果有人知道如何解决这个问题,通过修复崎岖的图片和文字未遂1
如何绘制图像在细胞外未遂2,我将非常感激。

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.

推荐答案

我终于找到了问题的解决方案,该解决方案是不是很好,但工作,当时的想法是绘制细胞项目直接借鉴的背景GridView和不GridView的童装/项目

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

我创建一个新的GridView为:

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

和我的孩子们 AbstractNote 我想补充 drawBackground 的方法,这个做那个背景我做什么,在画我的 AbstractNote 现在GridView的画布是更大的那么细帆布我在 AbstractNote

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天全站免登陆