拖动图像只会水平或垂直的机器人? [英] Drag an image only horizontally or vertically in android?

查看:117
本文介绍了拖动图像只会水平或垂直的机器人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想控制在Android上的图像的拖动方式。它应该只在一个方向上移动。我怎样才能控制它?

I want to control the dragging way of the image in android. It should be moved only in one direction. How can i control it?

推荐答案

首先,把滚动型 Horizo​​ntalScrollView 的ImageView 最里面的滚动型里面。

First, put a ScrollView inside a HorizontalScrollView, and the ImageView inside the innermost ScrollView.

层次结构如下所示:

  LinearLayout (ROOT)
  |
  +-- ScrollView (V)
       |
       +-- LinearLayout (1)
            |
            +-- HorizontalScrollView (H)
                |
                +-- LinearLayout (2)
                    |
                    +-- ImageView

让我解释一下:

And let me explain:

(V)在垂直方向上滚动而已。

(V) scrolls in vertical direction only.

(H)在水平方向上滚动而已。

(H) scrolls in horizontal direction only.

(1)(2)是用于线性布局紧跟任何ScrollViews。因为,一个滚动型只能承载一个直接子。

(1) and (2) are linear layouts used immediately following any ScrollViews. Because, a ScrollView can host only one direct child.

关于命名注:这里只有滚动型,而没有的VerticalScrollView

Note on naming: There's only "ScrollView", and not "VerticalScrollView"

什么当您将发生在的ImageView

,如果是水平的, Horizo​​ntalScrollView 将处理的动作,而滚动型都不会坐视不管。而如果动作是垂直的,在滚动型将处理的动作,而 Horizo​​ntalScrollView 都不会坐视不管。

Based on the very first direction of the gesture you make, if it's horizontal, the HorizontalScrollView will process the action, and the ScrollView will sit idle. And if the action was vertical, the ScrollView will process the action, and HorizontalScrollView will sit idle.

这篇关于拖动图像只会水平或垂直的机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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