Android菜鸟日记
29 杂记
一、LayoutInflater与findViewByID
findViewByID就是通常我们用来获取view方法。
前提是需要 当前activity已经setContentView()了。
如果是使用LayoutInflater
是有两种情况
情况一:
使用LayoutInFlater.from(context ct)获取LayoutInflater 对象
然后通过LayoutInflater.inflater(R.layout.xx,null);来获得view 对象。
情况二:
通过(LayoutInFlater)getSystemService(LAYOUT_INFLATER_SERVICE);来获取LayoutInflater 对象。
总结一下
findViewByID:是通过 view的id(R.id.xx) 来获取的。
LayoutInflater:是通过R.layout.xx是通过layout来获取的。
二、横竖屏切换
方法一:
AndroidMainIfest.xml里面的
<activity标签里写 android:screenOrientation属性>
方法二:
首先在Activity注册android:configChanges=true;
然后在代码中重写
onConfigurationChanged()函数。
当屏幕方向改变的时候就会调用此方法。
代码中写入
|
If(this.getResources().getConfigurartion().orientation==Configurartion.Orientation_Portrait) { //当竖屏时 } ………………………………………………………………………………………_LANDSCAPE { //当横屏时 } |
方法三:
这个方法意在:当横竖屏切换的时候会相应onSaveInstanceState()函数,然后重新砸入当前Activity,最后相应onRestoreInstanceState()函数。通过这两个函数进行屏幕横竖屏切换的处理。
2012-01-09
poolo
本文深入探讨Android开发中的布局加载方法,包括findViewByID和LayoutInflater的使用,以及如何实现横竖屏切换,通过配置Activity属性和自定义函数来确保应用在不同设备上稳定运行。
1万+

被折叠的 条评论
为什么被折叠?



