Всплывающее меню не настраивается в режиме привязки android - PullRequest
0 голосов
/ 23 апреля 2020

Я хочу показать всплывающее меню в представлении, в котором я надуваю всплывающий макет. Я использую всплывающий класс для всплывающих функций. Пока я не могу видеть всплывающее окно в представлении.

Я проверил много ответов в переполнении стека и попытался применить то же самое, но у меня не работает.

Вот мой класс всплывающих окон :

    public class PopUpClass {

        //PopupWindow display method

        //Create a View object yourself through inflater
        LayoutInflater inflater = (LayoutInflater) view.getContext().getSystemService(view.getContext().LAYOUT_INFLATER_SERVICE);
        View popupView = inflater.inflate(R.layout.popup_menu_layout, null);


        //Specify the length and width through constants
        int width = LinearLayout.LayoutParams.WRAP_CONTENT;
        int height = LinearLayout.LayoutParams.WRAP_CONTENT;

        //Make Inactive Items Outside Of PopupWindow
        boolean focusable = true;

        PopupWindow popupWindow = new PopupWindow(popupView,
                RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);



/*       popupWindow.showAtLocation(view,Gravity.RIGHT,
                view.getWidth() - (view.getWidth()*50)/100,
                view.getHeight() - (view.getHeight()*10)/100);

        popupWindow.showAsDropDown(view, 0,
                -view.getHeight()-popupView.getHeight());*/

        //Create a window with our parameters
  /*      final PopupWindow popupWindow = new PopupWindow(popupView, width,
                height, focusable);*/



     //   Set the location of the window on the screen
/*    popupWindow.showAtLocation(view,
            view.getWidth() - popupWindow.getWidth(),
               view.getWidth(), view.getHeight());*/
    }

Я вызываю всплывающее окно в адаптере, давая вид, по которому щелкаем.

holder.imageViewShare.setOnClickListener(new View.OnClickListener() {
            @Override public void onClick(View v) {

                        PopUpClass popUpClass = new PopUpClass();
                        popUpClass.showPopupWindow(v);
            }
        });

Вот мой макет фрагмента, который включает в себя виды общего доступа, например, et c. Я хочу открыть всплывающее окно для imageViewShare

http://schemas.android.com/apk/res/android "xmlns: app =" http://schemas.android.com/apk/res-auto "xmlns: tools =" http://schemas.android.com/tools "android: layout_width = "match_parent" android: layout_height = "match_parent" tools: context = ".QuotesFragment" android: background = "@ drawable / bubbles_theme">

        <RelativeLayout
            android:layout_width = "match_parent"
            android:layout_height = "match_parent"
            app:layout_constraintBottom_toBottomOf = "parent"
            app:layout_constraintEnd_toEndOf = "parent"
            app:layout_constraintStart_toStartOf = "parent"
            app:layout_constraintTop_toTopOf = "parent">

            <TextView
                android:id = "@+id/textView_quotes"
                android:layout_width = "250dp"
                android:layout_height = "300dp"
                android:layout_centerInParent = "true"
                android:fontFamily = "@font/open_sans_semibold_italic"
                android:gravity = "start|center_vertical"
                android:text = "Doing a same thing over and over again and expecting different results"
                android:textAlignment = "textStart"
                android:autoSizeTextType="uniform"
                android:textColor = "@android:color/white"
                android:textSize = "@dimen/text_size24" />

            <include
                android:id = "@+id/include2"
                layout = "@layout/share_save_like_layout"
                android:layout_width = "match_parent"
                android:layout_height = "60dp"
                android:layout_below = "@id/textView_quotes"
                android:layout_marginTop="@dimen/margin_20"
                android:layout_centerHorizontal = "true"
                app:layout_constraintEnd_toEndOf = "parent"
                app:layout_constraintStart_toStartOf = "parent" />

        </RelativeLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

Вот файл share_save_like_layout

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android = "http://schemas.android.com/apk/res/android"
    xmlns:app = "http://schemas.android.com/apk/res-auto"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:layout_width = "wrap_content"
    android:layout_height = "60dp">

    <ImageView
        android:id = "@+id/imageView_favourite"
        android:layout_width = "30dp"
        android:layout_height = "30dp"
        android:src = "@drawable/ic_favourite"
        android:layout_marginEnd="60dp"
        android:layout_marginRight = "60dp"
        android:layout_marginLeft="60dp"
        android:layout_marginStart="60dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@id/imageView_bookmark"
       />

    <ImageView
        android:id = "@+id/imageView_bookmark"
        android:layout_width = "30dp"
        android:layout_height = "30dp"
        android:src = "@drawable/ic_bookmark"
        android:layout_marginEnd="60dp"
        android:layout_marginRight = "60dp"
        android:layout_marginLeft="60dp"
        android:layout_marginStart="60dp"
        app:layout_constraintStart_toStartOf="@id/imageView_favourite"
        app:layout_constraintEnd_toEndOf="@id/imageView_share"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

    <ImageView
        android:id = "@+id/imageView_share"
        android:layout_width = "30dp"
        android:layout_height = "30dp"
        android:src = "@drawable/ic_share"
        android:layout_marginEnd="60dp"
        android:layout_marginRight = "60dp"
        android:layout_marginLeft="60dp"
        android:layout_marginStart="60dp"
        app:layout_constraintStart_toStartOf="@id/imageView_bookmark"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>


</androidx.constraintlayout.widget.ConstraintLayout>

Пожалуйста, ознакомьтесь с этим.

Вот как это выглядит enter image description here

Пожалуйста, помогите с предложениями. Спасибо.

...