How to disable behind view click event Framelayout

android view disable click event
android disable touch on view
android disable click on view programmatically
disable view
android fragment click through
framelayout remove view
android make view not clickable
how to disable button click in android

Here i have one view pager activity which has one imageview and 2 overlay bars. there overlay bars i made using android xml file layout itself.

Here my requirement is like that

1) single tap on view pager's imageview first time = show top and bottom rectangle overlaybar. 2) single tap on view pager's imageview second time = hide these overlays.

These both are functions like android gallary view type.

But here when these top and bottom layout bar displays at that time i want to use only buttons click only which buttons are declare within this layout.

But I am not getting success to achieve this thing.

Problems

1) when top or bottom bar is there if i can click on next or previous button than its takes event for behind imageview single tap touch event, And my bar is getting invisible. 2) Only wants declare buttons event only 3) Avoid imageview getting clicked when i touch to overlay bar.

In short when my top and bottom image bar appears at that time no touh event takes place for imageview from top and bottom image bar. I can click on imageview but not making clickable when i click on actually next or previous or share button.

So these are the problems which i am facing, Please help me .

Source code :

activity_pager_image.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <RelativeLayout
        android:id="@+id/rl_top_overlay"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/slideshow_bar"
        android:visibility="gone" >

        <TextView
            android:id="@+id/tv_top_overlay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:textIsSelectable="false" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/rl_bottom_overlay"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@drawable/slideshow_bar"
        android:visibility="visible" >

        <Button
            android:id="@+id/btn_left_arrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="35dp"
            android:background="@drawable/ic_left_arrow" />

        <Button
            android:id="@+id/btn_below_share"
            style="@style/normalText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="35dp"
            android:background="@drawable/ic_share"
            android:visibility="visible" />

        <Button
            android:id="@+id/btn_right_arrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="50dp"
            android:layout_toRightOf="@id/btn_left_arrow"
            android:background="@drawable/ic_right_arrow" />
    </RelativeLayout>

</FrameLayout>

item_pager_image.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <demo.android.library.imagezoom.ImageViewTouch
        android:id="@+id/image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:adjustViewBounds="true"
        android:contentDescription="@string/descr_image"
        android:scaleType="fitXY" />

</FrameLayout>

JAVA code

public class ImagePagerActivity extends BaseActivity {

    private static final String STATE_POSITION = "STATE_POSITION";
    private DisplayImageOptions options;
    private String[] imageUrls;
    private ViewPager pager;

    private static int sCounter = 0;

    private RelativeLayout mRlTopOverlayBar = null;
    private RelativeLayout mRlBottomOverlayBar = null;
    private TextView mPageNumberText = null;
    private Button mLeftArrow = null;
    private Button mRightArrow = null;

    int mPageCounter = 0;
    int mTotalImages = 0;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_pager);

        mRlTopOverlayBar = (RelativeLayout) findViewById(R.id.rl_top_overlay);
        mRlBottomOverlayBar = (RelativeLayout) findViewById(R.id.rl_bottom_overlay);

        mPageNumberText = (TextView) findViewById(R.id.tv_top_overlay);
        mLeftArrow = (Button) findViewById(R.id.btn_left_arrow);
        mRightArrow = (Button) findViewById(R.id.btn_right_arrow);

        Bundle bundle = getIntent().getExtras();
        String[] imageUrls = bundle
                .getStringArray(Constants.GALLARY_IMAGES_IMAGE_BUNDLE_KEY);

        mTotalImages = imageUrls.length;

        mPageCounter = bundle.getInt(
                Constants.GALLARY_IMAGE_POSITION_BUNDLE_KEY, 0);

        Log.d("TAG", "Pre Poistion " + mPageCounter);

        if (savedInstanceState != null) {
            mPageCounter = savedInstanceState.getInt(STATE_POSITION);
        }

        options = new DisplayImageOptions.Builder()
                .showImageForEmptyUri(R.drawable.photo_default)
                .showImageOnFail(R.drawable.ic_error).resetViewBeforeLoading()
                .cacheOnDisc().imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .displayer(new FadeInBitmapDisplayer(300)).build();

        pager = (ViewPager) findViewById(R.id.pager);
        pager.setAdapter(new ImagePagerAdapter(imageUrls));
        pager.setCurrentItem(mPageCounter);

        mLeftArrow.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // int setCounter = mPageCounter - 1;
                // if (setCounter >= 0) {

                // }
                pager.setCurrentItem(pager.getCurrentItem() - 1);

            }
        });

        mRightArrow.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                pager.setCurrentItem(pager.getCurrentItem() + 1);
                /*
                 * int setCounter = mPageCounter + 1; if (setCounter <
                 * mTotalImages) { pager.setCurrentItem(mPageCounter + 1); }
                 */
            }
        });
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        outState.putInt(STATE_POSITION, pager.getCurrentItem());
    }

    private class ImagePagerAdapter extends PagerAdapter {

        private String[] images;
        private LayoutInflater inflater;

        ImagePagerAdapter(String[] images) {
            this.images = images;
            inflater = getLayoutInflater();
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            ((ViewPager) container).removeView((View) object);
        }

        @Override
        public void finishUpdate(View container) {
        }

        @Override
        public int getCount() {
            return images.length;
        }

        @Override
        public Object instantiateItem(ViewGroup view, int position) {
            View imageLayout = inflater.inflate(R.layout.item_pager_image,
                    view, false);

            Log.d("TAG", "Poistion " + position);
            final ImageViewTouch imageView = (ImageViewTouch) imageLayout
                    .findViewById(R.id.image);

            final DeactivableViewPager viewPager = new DeactivableViewPager(
                    ImagePagerActivity.this);
            imageView.setOnScaleListener(new OnPageScaleListener() {

                @Override
                public void onScaleBegin() {
                    viewPager.deactivate();
                }

                @Override
                public void onScaleEnd(float scale) {
                    if (scale > 1.0) {
                        viewPager.deactivate();
                    } else {
                        viewPager.activate();
                    }
                }
            });

            imageView
                    .setSingleTapListener(new OnImageViewTouchSingleTapListener() {

                        @Override
                        public void onSingleTapConfirmed() {
                            Log.d("TAG", "setSingleTapListener");

                            sCounter++;
                            if (sCounter % 2 == 0) {
                                mRlTopOverlayBar.setVisibility(View.GONE);
                                mRlBottomOverlayBar.setVisibility(View.GONE);
                            } else {
                                mRlTopOverlayBar.setVisibility(View.VISIBLE);
                                mRlBottomOverlayBar.setVisibility(View.VISIBLE);
                                mRlBottomOverlayBar.setClickable(false);
                                mRlTopOverlayBar.setClickable(false);
                            }
                        }
                    });

            imageLoader.displayImage(images[position], imageView, options,
                    new SimpleImageLoadingListener() {
                        @Override
                        public void onLoadingStarted(String imageUri, View view) {
                            // spinner.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onLoadingFailed(String imageUri, View view,
                                FailReason failReason) {
                            String message = null;
                            switch (failReason.getType()) {
                            case IO_ERROR:
                                message = "Input/Output error";
                                break;
                            case DECODING_ERROR:
                                message = "Image can't be decoded";
                                break;
                            case NETWORK_DENIED:
                                message = "Downloads are denied";
                                break;
                            case OUT_OF_MEMORY:
                                message = "Out Of Memory error";
                                break;
                            case UNKNOWN:
                                message = "Unknown error";
                                break;
                            }
                            Toast.makeText(ImagePagerActivity.this, message,
                                    Toast.LENGTH_SHORT).show();

                            // spinner.setVisibility(View.GONE);
                        }

                        @Override
                        public void onLoadingComplete(String imageUri,
                                View view, Bitmap loadedImage) {
                            // spinner.setVisibility(View.GONE);
                        }
                    });

            ((ViewPager) view).addView(imageLayout, 0);
            return imageLayout;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view.equals(object);
        }

        @Override
        public void restoreState(Parcelable state, ClassLoader loader) {
        }

        @Override
        public Parcelable saveState() {
            return null;
        }

        @Override
        public void startUpdate(View container) {
        }

    }
}

image :

thanks

 imageView.setSingleTapListener(new OnImageViewTouchSingleTapListener() {
                    @Override
                    public void onSingleTapConfirmed() {
                        Log.d("TAG", "setSingleTapListener");

                        sCounter++;
                        if (sCounter % 2 == 0) {
                            mRlTopOverlayBar.setVisibility(View.GONE);
                            mRlBottomOverlayBar.setVisibility(View.GONE);
                            pager.requestFocus();
                        } else {
                            mRlTopOverlayBar.setVisibility(View.VISIBLE);
                            mRlBottomOverlayBar.setVisibility(View.VISIBLE);
                            mRlTopOverlayBar.requestFocus();
                            mRlBottomOverlayBar.requestFocus();
                            mRlBottomOverlayBar.setClickable(true);
                            mRlTopOverlayBar.setClickable(true);
                        }
                    }
                });

How to disable behind view click event Framelayout, By default, the layout view in Android (LinearLayout, RelativeLayout, etc) don't consume click events. I discovered this trying to show a new  74 How to disable behind view click event Framelayout; 28 Export the Contacts as VCF file; 19 Real life use of doubly linked list;

A better way is to set the top and bottom frame to be clickable, with:

android:clickable="true"

Doing so will make sure that the view/frame itself will trap all clicking events, and will not pass it through the view behind it. Note this method works for all layout/view/controls, but many controls (such as buttons) already have this function on by default.

How to Stop Tap Events From Passing Through an Android , Any other View added to the FrameLayout overlaps the previous View; An anonymous listener is created on the fly to handle click events for the is hidden behind it because in FrameLayout one View overlaps the other. 1) when top or bottom bar is there if i can click on next or previous button than its takes event for behind imageview single tap touch event, And my bar is getting invisible. 2) Only wants declare buttons event only 3) Avoid imageview getting clicked when i touch to overlay bar.

android:clickable="true" for top and bottom bar.

or give each FrameLayout an onClickListener.

FrameLayout | Laying Out Controls in Android Containers, (1) Put this view in another View container like frame layout and add padding to the amount you want to increase the touchable area of view. Then, set the click  By default, the layout view in Android (LinearLayout, RelativeLayout, etc) don’t consume click events. I discovered this trying to show a new fragment above another. Taps were registering on the non-visible fragment below. To fix this, add an attribute to the view to tell it to consume click events with android:clickable="true".

just add this to each of your framelayout view containers so that absorb the click:

  android:clickable="true"
    android:focusable="true"
    android:focusableInTouchMode="true"

Android change touch area of View by TouchDelegate, FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view,  The issue is with the fact that the fragment elements seem to have higher priority than the navigation drawer. As seen in the screenshot, once I attempt to open up the "0 fragment" it instead opts to register the click on the button behind the navigation drawer.

@gordon1hd1 answer is correct but for those who are still confused, I am adding my layout which contains a FrameLayout as parent and a LinearLayout and twoImageViews as childs.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">         
     <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/scroll_parent"
            android:orientation="horizontal" />
    <ImageView
        android:id="@+id/ivArrowLeft"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="4dp"
        android:src="@drawable/actionbar_back"
        android:layout_gravity="left|center_vertical"
        android:background="#3f808080"
        android:clickable="true"
        />
    <ImageView
        android:id="@+id/ivArrowRight"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="4dp"
        android:src="@drawable/actionbar_back"
        android:layout_gravity="right|center_vertical"
        android:background="#3f808080"
        android:rotation="180"
        android:clickable="true"
        />
</FrameLayout>

Previously, the Linearlayout was also intercepting touch events when either of ImageViews were pressed. Adding android:clickable="true" to both ImageViews resolved the issue.

If you are also facing this type of issue, add android:clickable="true" to the view you want to trap the clicking event.

FrameLayout, If a View (or a ViewGroup) has an OnTouchListener , then the touch event is line numbers are off now, but clicking the links will still get you to the right file. It is actually just a FrameLayout subclass, which is itself a subclass of ViewGroup . @subramanyamnuggu I do not adivce you to disable the click for the background layout(You should disable click event for all of the controls in the FrameLayout).I recommand you to set the FrameLayout to Invisible when progressBar was show.

How touch events are delivered in Android - Suragch, I have a Frame layout inside that Relative Layout and a Progress bar in side that. should disable click event for all of the controls in the FrameLayout). But do you still want to show the content of the Frame behind the progressBar? If so, I'd suggest to add the progressBar to a View that covers all the  Then for your custom view, set it's background image to the border.xml resource. That background will draw a black outline around the perimeter of your View. You should also comment out the onDraw() method for this test. \$\begingroup\$ I tried this, and the custom view is not overlapping the keypad view.

how to disable background when loading the progress bar , To implement View.OnClickListener in your Activity or Fragment, you have to override onClick method on your class. FrameLayout. FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to

Handling Click events in Button, The intention being that the user not be able to click or action any control until the upload is complete. Adding an overlay view was in itself less simple than I had expected. <FrameLayout android:id="@android:id/tabcontent" ACTION_DOWN event to have occurred before, and an MotionEvent. JQuery: Disable button after click event. This is a short guide on how to disable a button with JQuery after it has been clicked. This kind of operation can come in handy if you want to make sure that a button is only clicked once; or if you want to disable a button while an Ajax request is being carried out.

Comments
  • why anybody do downvote?
  • I know this is 5 years too late, but what I discovered is your homescreen should be a fragment. Don't add controls to 'activity_main' or 'content_main' other than a framelayout to hold fragments. Adding controls to the main activity's layout will cause overlaying fragments to fire events for the main activity's controls when the same coordinates are pressed. Set each fragment's parent layout to 'android:clickable="true"'.
  • This works only if the lower view is not a button. Otherwise the button is still picking up the click event.
  • Should be the accepted answer. The current accepted answer is a hack
  • Well, doesn't work for me, the listview behind it still gets tapped
  • To test this if you turn on Accessiblity/Talkback then you would see the items selected on the back of the screen
  • Is there a way to do this programmatically?