How to stop scrolling gallery?

I have a gallery (images) in RelativeLayout, and if users click on it, three Buttonsand will appear TextView. I did it with a visible property, which means that three Buttonsand TextViewdeclared invisible in the xml file, and then onClick() Gallerymakes it visible using setVisibility(0). works great, but I want it to Gallerystop scrolling in Buttonsand out TextView.

Is there any way to do this?

+3
source share
1 answer

If you want to enable / disable gallery scrolling, you can use the class as follows:

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;
  }

}

Gallery , : , D-pad. , , . - :

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

/ :

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

Source: https://habr.com/ru/post/1762672/


All Articles