Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PopupMenu click causing RecyclerView to scroll

I have an overflow button inside a CardView in Recyclerview. Whenever I am clicking the button,I show a popup menu but also RecyclerView is scrolling down one item. Can anyone please help me stop this unwanted scrolling?

Basically I am trying to replicate the same overflow button behavior as in Playstore.

Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp">

<android.support.v7.widget.CardView
    android:id="@+id/cv_tracks"
    android:layout_width="match_parent"
    android:layout_height="65dp"
    >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="60dp">

        <ImageView
            android:id="@+id/ivTracks"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/unknown"
           />
        <Button
            android:id="@+id/imgbtn_overflow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:drawableTop="@drawable/ic_overflow"
            android:paddingLeft="25dp"
            android:paddingRight="20dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" /> 
 </RelativeLayout>
 </android.support.v7.widget.CardView>
 </RelativeLayout>

Adapter:

@Override
public void onBindViewHolder(final TracksViewHolder tracksViewHolder, int i) {

    tracksViewHolder.imgBtnOverflow.setTag(i);
    tracksViewHolder.imgBtnOverflow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Creating the instance of PopupMenu
            final int position = (Integer) v.getTag();

            PopupMenu popup = new PopupMenu(mContext,tracksViewHolder.imgBtnOverflow);

            //Inflating the Popup using xml file
            popup.getMenuInflater()
                    .inflate(R.menu.popup_menu_overflow, popup.getMenu());


            //registering popup with OnMenuItemClickListener
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                public boolean onMenuItemClick(MenuItem item) {

                 if(mPopUpClick!=null)
                     mPopUpClick.actionOnPopUpItemClick(position,item,songs.get(position));
                    return true;
                }
            });

            popup.show(); //showing popup menu
        }
    });

}

UPDATE: Got the issue .When the popup menu displays,it slides the list down so as to display the whole dropdown. How to adjust popup to display up/down depending on the space available?

like image 728
Siju Avatar asked Apr 06 '15 15:04

Siju


1 Answers

Tried using android.widget.PopupMenu instead of android.support.v7.widget.PopupMenu and Voila, it works. So is it a bug in Support library. Can great developers out here confirm the same?

like image 134
Siju Avatar answered Sep 19 '22 05:09

Siju