我正在编写一个应用程序,在该应用程序中,当一个活动进入后台时,它会使一个活动变小,并在单击它时调整它的大小。 基本上我想要一个像Skype视频调用浮动窗口的浮动窗口。 我试图为主要活动添加一个子活动,但是我再也没有能力再创建另一个活动,所以我的想法是在转到后台时将当前活动设置为小,并在单击时调整其大小。 为了做小,我这样做
//Get the window
Window window = getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,WindowManager.LayoutParams.FLAG_DIM_BEHIND);
// Params for the window.
// You can easily set the alpha and the dim behind the window from here
WindowManager.LayoutParams params = window.getAttributes();
params.alpha = 1.0f; // lower than one makes it more transparent
params.dimAmount = 0f; // set it higher if you want to dim behind the window
window.setAttributes(params);
// Gets the display size so that you can set the window to a percent of that
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
// You could also easily used an integer value from the shared preferences to set the percent
if (height > width) {
window.setLayout((int) (width * .35), (int) (height * .30));
} else {
window.setLayout((int) (width * .20), (int) (height * .35));
}
现在我想在窗口上设置onclicklistener,使点击时更大。 感谢您的帮助。