最显而易见的方式就是改变Window的尺寸,所以这里需要以下这段代码:
public void onAttachedToWindow() {
super.onAttachedToWindow();
if (getResources().getBoolean(R.bool.is_tablet) && mOpenAsSmallWindow) {
final View view = getWindow().getDecorView();
final WindowManager.LayoutParams lp = (WindowManager.LayoutParams) view.getLayoutParams();
lp.gravity = Gravity.CENTER;
lp.width = mActivityWindowWidth;
lp.height = mActivityWindowHeight;
getWindowManager().updateViewLayout(view, lp);
}
}
添加透明功能
在实现了Activity的尺寸和大小都改变后,现在就要让它透明了。可以给这个平板上的Activity主题添加这个属性:
这个属性值可以使Activity背景透明。
参考下面方法:
WindowManager wm;
WindowManager.LayoutParams wmlp;
LinearLayout linear;
EditText t;
wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wmlp = new WindowManager.LayoutParams();
wmlp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
wmlp.gravity = Gravity.TOP|Gravity.LEFT;
wmlp.format = PixelFormat.RGBA_8888;
wmlp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_FULLSCREEN|WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
wmlp.x = 0;//悬浮窗左上角的x坐标
wmlp.y = 0;//悬浮窗左上角的坐标
wmlp.width = 50;//宽
wmlp.height = 30;//高
linear = new LinearLayout(getApplicationContext());//悬浮窗显示的布局
linear.setGravity(Gravity.BOTTOM|Gravity.LEFT);
//组件
t = new TextView(getApplicationContext()); //文本
t.setTextColor(Color.RED);//文本颜色
t.setText("哈哈");
linear.addView(t);//将textview添加进布局
wm.addView(linear,wmlp); // 窗口管理器添加这个部件