规模图库所选项目 [英] Scale selected item in Gallery

查看:97
本文介绍了规模图库所选项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你知道我怎么能缩放所选项目的画廊?我知道,很明显的getScale()和getAlpha()从0.9 SDK中删除。所以,我怎么能达到同样的效果呢?

Do you know how can I scale the selected item in a Gallery? I know that apparently getScale() and getAlpha() were removed from 0.9 SDK. So how could I accomplish the same effect?

感谢

推荐答案

也许是来不及回答,但我发现这个问题寻找别的​​东西的时候。

Maybe it's too late to answer, but I found this question when searching something else.

我通过具有自定义的画廊和覆盖getChildStaticTransformation(),并加入一些其他的事情做了。

I did it by having a custom gallery and overriding getChildStaticTransformation() and adding some other things.

下面是一个例子。

private int centerOfGallery;

public CustomGallery(Context context) {
    super(context);
    init();
}

public CustomGallery(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

public CustomGallery(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
}

private void init() {
    setStaticTransformationsEnabled(true);
}

private int getCenterWidthOfView(View child) {
    return child.getLeft() + child.getWidth() / 2;
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    centerOfGallery = (w - getPaddingLeft() - getPaddingRight()) / 2 + getPaddingLeft();
}

@Override
protected boolean getChildStaticTransformation(View child, Transformation t) {
    mCamera.save();
    final Matrix matrix = t.getMatrix();
    final int centerWidthOfChild = getCenterWidthOfView(child);
    final int delta = centerOfGallery - centerWidthOfChild;

    final float scale = (float)(maxScale - Math.abs(delta) * 0.5f / centerOfGallery);
    mCamera.getMatrix(matrix);
    matrix.preScale(scale, scale);
    matrix.preTranslate(-1, -1);
    matrix.postTranslate(1, 1);
    mCamera.restore();

    if (version >= 15) { // For Jelly Bean hack
        child.invalidate();
    }

    return true;
}

在哪里
maxScale是你想要的最大规模​​为选定的项目(例如1.5F)

where maxScale is the maximum scale you want for selected item (e.g. 1.5f)

之后,缩放时它们必须注意在库项目之间的间距。您可以使用setSpacing()如果必要的。

After that, be careful about the spacing between items in the gallery when scaling them. You can use setSpacing() if necessary.

希望这有助于

勒布

这篇关于规模图库所选项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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