水平和垂直滑动的动态视图

5

在此输入图片描述

请查看上述视图。

我需要相应地创建一个视图,当我们从左向右滑动时,图片将出现,就像从右向左滑动一样。 当我从上到下滑动时,将出现一个 Web 视图,并且向下滑动图片将出现。 所有数据如图像和 Web URL 将是动态的,数据将来自服务器。 此外,我还必须在其中应用下拉刷新的概念。

我已经阅读了此链接,并成功实现了它,但它不是按照预期,并且它具有许多限制。

请告诉我这种视图是否可行。

2个回答

1

有一种方法可以不使用任何库来完成这个操作。

在您的xml文件中设计另一个布局,并将所有您想要在滑动时显示的小部件放置在其中,然后应用左到右和上到下的滑动动画,根据您的需要进行设置。之后,借助手势检测器,您可以获得滑动事件并执行您的任务。

这是我的代码

Animation Left slide
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromXDelta="100%"
    android:toXDelta="0%" >
</translate>

Animation Right slide
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromXDelta="-100%"
    android:toXDelta="0%" >
</translate>

Animation Slide up
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromYDelta="100%"
    android:toYDelta="0%" >
</translate>

Animation Slide Down
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromYDelta="-100%"
    android:toYDelta="0%" >
</translate>

用于动画的类文件中使用的代码

case SimpleGestureFilter.SWIPE_RIGHT:
    ScreenAnimation.setVisibility(View.VISIBLE);
    ScreenAnimation.startAnimation(RightSwipe);

    break;
case SimpleGestureFilter.SWIPE_LEFT:
    ScreenAnimation.setVisibility(View.VISIBLE);
    break;
case SimpleGestureFilter.SWIPE_DOWN:
    ScreenAnimation.setVisibility(View.VISIBLE);
    ScreenAnimation.startAnimation(DownSwipe);
    break;
case SimpleGestureFilter.SWIPE_UP:
    ScreenAnimation.setVisibility(View.VISIBLE);
    ScreenAnimation.startAnimation(UpSwipe);
    break;

0

有一个名为TwoWayGridView的开源组件。它提供了水平和垂直滚动。也许你可以自定义它以适应你的需求。

另一种方法是使用GestureDetector并自己跟踪轨迹。Android开发者网站上还有一个示例项目,转到培训→用户输入的最佳实践→使用触摸手势(我不能发布超过两个链接)。起初看起来很复杂,但然后你可以自定义每个手势,这样你就可以区分向上和向下滑动等不同手势。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接