如何停止滚动图片库吗? [英] how to stop scrolling gallery?

查看:108
本文介绍了如何停止滚动图片库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 RelativeLayout的,如果用户点击它,三按钮并出现的TextView 。我与可见性做到了,这意味着三个按钮的TextView 的声明在XML为不可见-file和后来的的onClick()图库使其可见与 setVisibility(0 )。那工作正常,但我想在图库停止在按钮滚动的TextView 在前面。

I've got a gallery (images) in a RelativeLayout and if the users click on it, three Buttons and a TextView appears. I made it with the visible-property, that means the three Buttons and the TextView are declared as invisible in the xml-file and later the onClick() of the Gallery makes it visible with setVisibility(0).That works fine, but I want the Gallery to stop scrolling during the Buttons and the TextView are in front.

有没有办法做到这一点?

Is there any way to do this?

推荐答案

如果您希望能够启用/禁用画廊的滚动,你可以使用这样的类:

If you want to be able to enable/disable scrolling of the Gallery, you could use class like this:

public class ExtendedGallery extends Gallery {

  private boolean stuck = false;

  public ExtendedGallery(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
  }

  public ExtendedGallery(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  public ExtendedGallery(Context context) {
    super(context);
  }

  @Override
  public boolean onTouchEvent(MotionEvent event) {
    return stuck || super.onTouchEvent(event);
  }

  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
      return stuck || super.onKeyDown(keyCode, event);
    }
    return super.onKeyDown(keyCode, event);
  }

  public void setScrollingEnabled(boolean enabled) {
    stuck = !enabled;
  }

}

据图库源$ C ​​$ C,还有一些开始滚动两个事件类型:全屏触摸和按键,pssed在D垫$ P $。所以,如果你想禁用滚动,你可以截获这些事件。然后,使用这样的事情在你的布局:

According to the Gallery source code, there are two event types that start the scrolling: screen touch and the key, pressed on D-pad. So you could intercept these events if you want to disable scrolling. Then use something like this in your layout:

<your.package.name.ExtendedGallery
    android:id="@+id/gallery"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />

然后就可以启用/禁用该库在任何时间滚动:

Then you can enable/disable scrolling of that gallery at any time:

ExtendedGallery mGallery = (ExtendedGallery) findViewById(R.id.gallery);
mGallery.setScrollingEnabled(false); // disable scrolling

这篇关于如何停止滚动图片库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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