Android Q&A

1.Q:SurfaceHolder.Callback() 中 public voidsurfaceCreated(SurfaceHolder holder) 不被回调的原因?

A:SurfaceView中包含一个surface,可以用getHolder().addCallback(mSurfaceHoldercallback);的方法添加回调函数,在surface创建的时候会调用public void surfaceCreated(SurfaceHolder holder),但是如果SurfaceViewxml中布局,则SurfaceViewoncreat()中被加载,这个时候如果在程序中添加addCallback,则surfaceCreated方法有可能不被回调,因为添加回调的时候surface已经被加载好了。


2.Q:Android中每次屏幕方向切换时都会重启Activity,所以应该在Activity销毁前保存当前活动状态,在Activity再次onCreate的时候载入配置。如何避免转屏时重启Activity:?

A:在AndroidManifest.xml中定义屏幕方向(给Activity加上android:configChanges=”keyboardHidden|orientation)。在需要控制屏幕显示方向的Activity中重写

onConfigurationChanged(ConfigurationnewConfig)方法。


3.Q:Android的View中invalidate()和requestLayout会触发哪些方法?

A:图解如下:


4.Q:为什么有时候在程序里获取View的宽度和高度会返回0?

A:在activity中可以调用View.getWidth、View.getHeight()、View.getMeasuredWidth() 、View.getMeasuredHeight()来获得某个view的宽度或高度,但是在onCreate()、onStrart()、onResume()方法中会返回0,这是应为当前activity所代表的界面还没显示出来没有添加到WindowPhone的DecorView上或要获取的view没有被添加到DecorView上或者该View的visibility属性为gone 或者该view的width或height真的为0  所以只有上述条件都不成立时才能得到非0的width和height  

5 Q:AndroidManifest.xml中android:versionCode 和 android:versionName的区别

android:versionCode:

An internal version number. This number is used only to determine whether one version is more recent than another, with higher numbers indicating more recent versions. This is not the version number shown to users; that number is set by the versionName attribute.

The value must be set as an integer, such as "100". You can define it however you want, as long as each successive version has a higher number. For example, it could be a build number. Or you could translate a version number in "x.y" format to an integer by encoding the "x" and "y" separately in the lower and upper 16 bits. Or you could simply increase the number by one each time a new version is released.

android:versionName:

The version number shown to users. This attribute can be set as a raw string or as a reference to a string resource. The string has no other purpose than to be displayed to users. The versionCode attribute holds the significant version number used internally.

6 Q:AndroidManifest.xml中android:uses-permission和 android:uses-feature的区别

<uses-permission> says "hey, Android (and associated distribution channels), please ask the user to allow me to do X". <uses-feature> says "hey, Android (and associated distribution channels), I am interested in running on hardware with feature Y".

<uses-feature> may filter you out of the Play Store (and other channels), if the hardware does not meet your requirements, but the user doesn't get involved.








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值