请问我这个PopupWindow怎么在这个底部凸起图片上面弹出?我这样写始终不行

想实现的效果:
图片描述
布局:
<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
tools:context="com.demaxiya.activity.MainActivity">

<RadioGroup
    android:id="@+id/rg_tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="#11000000"
    android:clipChildren="true"
    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>

<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/radiobutton_switch_game_normal" />

</RelativeLayout>
代码:
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:弹出window显示在底部button上面
    int[] location = new int[2];
    mSwitchGameNormal.getLocationOnScreen(location);//mSwitchGameNormal为凸起的图片
    mPopupWindow.showAtLocation(mSwitchGameNormal, Gravity.NO_GRAVITY, location[0], location[1]-mPopupWindow.getHeight());
    mPopupWindow.showAtLocation(MainActivity.this.findViewById(R.id.main), 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);
        }
    });

阅读 2.5k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏