拖动图像只会水平或垂直的机器人?只会、拖动、机器人、图像

2023-09-06 13:09:02 作者:樱小珞

我想控制在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.

 
精彩推荐
图片推荐