Could you tell me how to make my PopupWindow pop up on RadioGroup?

after popping up, window needs to be close to RadioGroup, not to the top of the screen.
layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="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"
    android:clipChildren="false"
    tools:context="com.de.activity.MainActivity">

    <RadioGroup
        android:id="@+id/rg_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:clipChildren="true"
        android:background="-sharpFFFFFF"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/rb_home"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:button="@null"
            android:drawableTop="@drawable/home_button_selector"
            android:gravity="center"
            android:paddingTop="5dp"
            android:text=""
            android:textColor="@drawable/main_radiobutton_text_color_selector" />

        <RadioButton
            android:id="@+id/rb_channel"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:button="@null"
            android:drawableTop="@drawable/channel_button_selector"
            android:gravity="center"
            android:paddingTop="5dp"
            android:text=""
            android:textColor="@drawable/main_radiobutton_text_color_selector" />

        <View
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_gravity="bottom"
            android:layout_weight="1" />

        <RadioButton
            android:id="@+id/rb_discovery"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:button="@null"
            android:drawableTop="@drawable/discovery_button_selector"
            android:gravity="center"
            android:paddingTop="5dp"
            android:text=""
            android:textColor="@drawable/main_radiobutton_text_color_selector" />

        <RadioButton
            android:id="@+id/rb_mine"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:button="@null"
            android:drawableTop="@drawable/mine_button_selector"
            android:gravity="center"
            android:paddingTop="5dp"
            android:text=""
            android:textColor="@drawable/main_radiobutton_text_color_selector" />

    </RadioGroup>

    <View
        android:layout_above="@id/rg_tabs"
        style="@style/HorizontalLine"/>

    <FrameLayout
        android:id="@+id/fl_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/rg_tabs">

    </FrameLayout>

    <!---->
    <ImageView
        android:id="@+id/iv_switch_game_normal"
        android:layout_width="wrap_content"
        android:layout_height="70dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:src="@mipmap/king_honor" />

</RelativeLayout>

Class partial code:

   private void showTypeWindow() {
        View typeWindow = LayoutInflater.from(MainActivity.this).inflate(R.layout.window_type, null);
        mPopupWindow = new PopupWindow(typeWindow, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        mPopupWindow.setBackgroundDrawable(new BitmapDrawable());     //popupwindow
        mPopupWindow.setFocusable(true);
        //TODO:windowbutton
        int[] location = new int[2];
        mSwitchGameNormal.getLocationOnScreen(location);
        mPopupWindow.showAtLocation(mSwitchGameNormal, Gravity.NO_GRAVITY, location[0], location[1]-mPopupWindow.getHeight());
       // mPopupWindow.showAtLocation(mSwitchGameNormal, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); //popupwindow
        WindowManager.LayoutParams lpType = getWindow().getAttributes(); // 
        lpType.alpha = 0.7f;
        getWindow().setAttributes(lpType);
        mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 1f;
                getWindow().setAttributes(lp);
            }
        });
        TextView heroUnion = typeWindow.findViewById(R.id.rl_hero_union);
        TextView kingHonor = typeWindow.findViewById(R.id.rl_king_honor);
        TextView wildrnessAction = typeWindow.findViewById(R.id.rl_wilderness_action);
        heroUnion.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "", Toast.LENGTH_SHORT).show();
                mSwitchGameNormal.setImageResource(R.mipmap.hero_union);
                mPopupWindow.dismiss();
            }
        });
        kingHonor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "", Toast.LENGTH_SHORT).show();
                mSwitchGameNormal.setImageResource(R.mipmap.king_honor);
                mPopupWindow.dismiss();
            }
        });
        wildrnessAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "", Toast.LENGTH_SHORT).show();
                mSwitchGameNormal.setImageResource(R.mipmap.wilderness_action);
                mPopupWindow.dismiss();
            }
        });
    }

desired effect:

Feb.27,2021

I've done this before, and I can only give you an idea

implementation idea: first set the transparent pop-up popupWindow, to measure its width and height, calculate the corresponding offset, and then pop up popupWindow in the exact position

.

if you already know the size of the popupWindow to pop up, calculate the location directly, and then pop

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e923da-4717c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e923da-4717c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?