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: