android - 如何使(矩阵?)转换永久成为 RecyclerView

标签 android android-layout transformation matrix-transform

我目前正在使用一个具有水平LinearLayoutRecyclerViewRecyclerView 占据了整个屏幕:

enter image description here

我正在寻找对 RecyclerView 进行修复转换的方法,如下所示:

enter image description here

注意,转变就像“下沉”或“垮台”,以产生“深刻”的效果。由于项目的大小可以改变,我需要一个永久的转换,这就是为什么我想在 RecyclerView

中进行它

有什么办法吗?也许有一种方法可以在 onDraw 上做到这一点??

提前非常感谢您。

问候。

拉斐尔。


添加:

我想注意到PageTransformer做了类似的事情。事实上,我想要的东西与三星 Galaxy S3 在使用其中一个启动器(使用 ViewPager)滚动时所做的非常相似,但我想修复该转换:

enter image description here


我在尝试什么?

我正在尝试滚动 RecyclerView 的大型水平适配器,但我想稍微“折叠” View 以产生“圆柱体”的一点印象。

最佳答案

创建一个扩展RecyclerView的类并重写其dispatchDraw(或draw)方法,使用Matrix#setPolyToPoly 要进行透视变换,下面的代码会产生类似“星球大战”效果的效果,您需要调用 setPolyToPoly 两次,并将 Matrix 应用于自定义 View 的两半:

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        final float DELTAX = w * 0.15f;
        float[] src = {
                0, 0, w, 0, w, h, 0, h
        };
        float[] dst = {
                0, 0, w, 0, w - DELTAX, h, DELTAX, h
        };
        matrix.setPolyToPoly(src, 0, dst, 0, 4);
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        canvas.save();
        canvas.concat(matrix);
        super.dispatchDraw(canvas);
        canvas.restore();
    }

关于android - 如何使(矩阵?)转换永久成为 RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33656750/

相关文章:

android - 如何制作Activity,不覆盖全屏

python - 反序列化棉花糖中的嵌套字段

xml - 在 XPath 表示法中,表达式//*[self::SOME_LABEL] 与//SOME_LABEL 有何不同?

android - 从服务启动 Activity 花费的时间太长

android - AutoCompleteTextView 在适配器更改时隐藏和显示下拉列表

android - 将多个 firebase 目录中的所有帖子显示到 recyclerView 中

java - 在我的井字游戏代码中,动画选项在按下重置按钮后不起作用

android - 与工具栏、多屏布局等相关

android - 如何以编程方式获取根布局并将其设置为内容 View

transformation - 计算 2 3D 笛卡尔坐标系之间转换的四元数