在一个8寸屏的Android平板电脑上开发应用程序(游戏程序),开始的时候,总是不能全屏显示,也不知道怎么设置才可以。
本来LCD应该是800*600的,但总是得到600*600的结果。
修改代码如下:
布局文件:
<? <strong>xml</strong> version = "1.0" encoding = "utf-8" ?> |
02 | < <strong>manifest</strong> xmlns:android = "<a style="color: #336699; text-decoration: none;" href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>" |
04 | android:versionCode = "1" |
05 | android:versionName = "1.0" > |
06 | < <strong>application</strong> android:icon = "@drawable/icon" android:label = "@string/app_name" > |
07 | < <strong>activity</strong> android:name = ".myactivity" |
08 | android:screenOrientation = "portrait" |
09 | android:label = "@string/app_name" > |
10 | < <strong>intent-filter</strong> > |
11 | < <strong>action</strong> android:name = "android.intent.action.MAIN" /> |
12 | < <strong>category</strong> android:name = "android.intent.category.LAUNCHER" /> |
13 | </ <strong>intent-filter</strong> > |
14 | </ <strong>activity</strong> > |
16 | </ <strong>application</strong> > |
17 | < <strong>supports-screens</strong> android:largeScreens = "true" |
18 | android:normalScreens = "true" |
19 | android:smallScreens = "true" |
20 | android:anyDensity = "true" /> |
21 | </ <strong>manifest</strong> > |
后面加的<supports-screens android:largeScreens="true".../>就可以解决这个问题了
Activity中的代码:
01 | <strong>public</strong> <strong>class</strong> myactivity <strong>extends</strong> Activity { |
02 | <strong>public</strong> myview v; |
03 | /** Called when the activity is first created. */ |
05 | <strong>public</strong> <strong>void</strong> onCreate(Bundle savedInstanceState) { |
06 | <strong>super</strong> .onCreate(savedInstanceState); |
07 | // setContentView(R.layout.main ); |
08 | requestWindowFeature(Window.FEATURE_NO_TITLE); |
09 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, |
10 | WindowManager.LayoutParams.FLAG_FULLSCREEN); |
12 | WindowManager windowManager = getWindowManager(); |
13 | Display display = windowManager.getDefaultDisplay(); |
14 | <strong>int</strong> w = display.getWidth(); |
15 | <strong>int</strong> h = display.getHeight(); |
16 | v= <strong>new</strong> myview( <strong>this</strong> ,w,h); |
总结:
主要就是去掉默认显示的标题和设置好全屏即可。
在Activity的onCreate方法中添加如下两行代码即可:
//去掉标题显示
requestWindowFeature(Window.FEATURE_NO_TITLE);
//全屏显示
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREAN,
WindowManager.LayoutParams.FLAG_FULLSCREAN)
android应用全屏方法暂时总结两种:
一.在代码中修改,效果就是先短暂显示状态栏然后再全屏:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//无title
requestWindowFeature(Window.FEATURE_NO_TITLE);
//全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.initscreen);
设置全屏的代码必须在设置显示界面之前,不然会报错,本例中就是在setContentView(R.layout.initscreen);之前
第二种方法:在配置文件manifest中修改,不会有显示状态栏的问题,可以马上全屏
添加如下一行配置:
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"