40

我正在网上冲浪,寻找在 Android 上翻页的好效果,但似乎没有。由于我正在学习该平台,因此能够做到这一点似乎是一件好事。

我设法在这里找到了一个页面:http ://wdnuon.blogspot.com/2010/05/implementing-ibooks-page-curling-using.html

- (void)deform
{
  Vertex2f  vi;   // Current input vertex
  Vertex3f  v1;   // First stage of the deformation
  Vertex3f *vo;   // Pointer to the finished vertex
CGFloat R, r, beta;
  for (ushort ii = 0; ii < numVertices_; ii++)
  {
    // Get the current input vertex.
    vi    = inputMesh_[ii];                       
    // Radius of the circle circumscribed by vertex (vi.x, vi.y) around A on the x-y plane
    R     = sqrt(vi.x * vi.x + pow(vi.y - A, 2)); 
    // Now get the radius of the cone cross section intersected by our vertex in 3D space.
    r     = R * sin(theta);                       
    // Angle subtended by arc |ST| on the cone cross section.
    beta  = asin(vi.x / R) / sin(theta);       

// *** MAGIC!!! ***
v1.x  = r * sin(beta);
v1.y  = R + A - r * (1 - cos(beta)) * sin(theta); 
v1.z  = r * (1 - cos(beta)) * cos(theta);
// Apply a basic rotation transform around the y axis to rotate the curled page.


 // These two steps could be combined through simple substitution, but are left
    // separate to keep the math simple for debugging and illustrative purposes.
    vo    = &outputMesh_[ii];
    vo->x = (v1.x * cos(rho) - v1.z * sin(rho));
    vo->y =  v1.y;
    vo->z = (v1.x * sin(rho) + v1.z * cos(rho));
  }  
}

这给出了 iPhone 的示例(上面)代码,但我不知道如何在 android 上实现它。那里的任何数学大神都可以帮助我了解如何在 Android Java 中实现这一点。

是否可以使用本机绘图 API,我是否必须使用 openGL?我可以以某种方式模仿这种行为吗?

任何帮助,将不胜感激。谢谢。

****************编辑********************************* *************

我在 Android API 演示中找到了一个位图网格示例:http: //developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/BitmapMesh.html

也许有人可以帮助我解决一个方程式,只需将右上角向内折叠在页面上,以创建类似的效果,我以后可以应用阴影来增加它的深度?

4

3 回答 3

31

我目前正在使用 OpenGL ES 对 Android 上的页面卷曲效果进行一些实验。这实际上是一个草图,但可能会给出一些想法如何根据您的需要实现页面卷曲。如果您对 3D 页面翻转实现感兴趣。

至于您所指的公式-我尝试过并且不太喜欢结果。我想说它根本不适合小屏幕,并开始破解一个更简单的解决方案。

代码可以在这里找到: https ://github.com/harism/android_page_curl/

在写这篇文章时,我正在决定如何实现“假”软阴影——以及是否创建一个合适的应用程序来展示这个页面卷曲效果。此外,这几乎是我做过的为数不多的 OpenGL 实现之一,不应过多地作为一个恰当的例子。

于 2011-04-11T23:44:06.477 回答
29

我刚刚创建了一个开源项目,它使用原生画布在 2D 中进行页面卷曲模拟:https ://github.com/moritz-wundke/android-page-curl 我仍在努力添加适配器等使其可用作独立视图。

  • 编辑:链接已更新。
  • 编辑:丢失的文件已被推送到回购。
于 2011-02-27T21:01:47.887 回答
0

我很确定,您必须使用 OpenGL 才能获得不错的效果。基本 UI 框架的功能非常有限,您只能使用动画对 View 进行基本的转换(alpha、translate、rotate)。

但是,可以使用 FrameLayout 和其中的自定义视图在 2D 中模仿类似的东西。

于 2010-10-12T08:59:03.337 回答