1.编程方式
public void setFullScreenMethod1(boolean isFullScreen) {
if (isFullScreen) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
//也可以用下面的清除Flag
//getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
public void setFullScreenMethod2(boolean isFullScreen) {
if (isFullScreen) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
2.配置theme方式
也可以在AndroidMenifest.xml中配置。在application或者activity元素中加上下面属性
<activity android:name="XXX" android:theme="@android:style/Theme.NoTitleBar" /> <activity android:name="XXX" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
3.用style方法
在styles.xml文件中定义下面style
<style name="FullScreenTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
在 AndroidMenifest.xml使用
<activity android:name="XXX" android:theme="@android:style/FullScreenTheme" />
Sencha Touch里的布局有五种
o hbox
o vbox
o card
o fit
o auto[默认]
实际上可以分为Box布局和Fit布局两种。
Sencha touch里的布局应该理解为:该控件内部子项的排列方式。
我们今天先来看看box布局
Box布局
顾名思义,box布局就是一个个的box组成的。
hbox: 水平排列、垂直居中、靠左置顶
vbox: 竖直堆叠、水平居中、靠上置顶
hbox:
Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady : function() {
var pnl = new Ext.Panel({
fullscreen: true,
layout: 'hbox',
items:[
{xtype:'button',text:'按钮1'},
{xtype:'button',text:'按钮2'},
{xtype:'button',text:'按钮3'}
]
});
}
});
vbox:
将以上的hbox改为vbox
但是,只是知道这些,还不足以玩转box布局,下面让我们看看其他常见的box布局实例。
vbox变型:
Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady : function() {
var pnl = new Ext.Panel({
fullscreen: true,
layout: 'vbox',
defaults: {
flex: 1
},
items:[
{xtype:'button',text:'按钮1'},
{xtype:'button',text:'按钮2'},
{xtype:'button',text:'按钮3'}
]
});
}
});
关于这里的flex,sencha Touch使用了css3中的弹性和模型,所以大家如果有兴趣可以看看 扩展阅读:css3中的弹性盒模型
vbox变型2:
在上面代码的defaults中加入width : '100%',得到下图
了解以上内容之后,我们来想想经典的九宫格布局如何实现吧!
相必大家也已经心中有数了。
经典的九宫格布局:
Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady : function() {
var pnl = new Ext.Panel({
fullscreen: true,
layout: 'vbox',
defaults: {
flex: 1,
width: '100%',
defaults: {
flex: 1,
height: '100%'
}
},
items:[{
xtype: 'panel',
layout: 'hbox',
items:[
{xtype:'button',text:'按钮1'},
{xtype:'button',text:'按钮2'},
{xtype:'button',text:'按钮3'}
]
},{
xtype: 'panel',
layout: 'hbox',
items:[
{xtype:'button',text:'按钮4'},
{xtype:'button',text:'按钮5'},
{xtype:'button',text:'按钮6'}
]
},{
xtype: 'panel',
layout: 'hbox',
items:[
{xtype:'button',text:'按钮7'},
{xtype:'button',text:'按钮8'},
{xtype:'button',text:'按钮9'}
]
}]
});
}
});
嫌紧挨着不舒服?别急,我们还有些属性没用上!你没有猜错那就是-----margin、padding!你知道怎么做的!
松散九宫格:
Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady : function() {
var pnl = new Ext.Panel({
fullscreen: true,
layout: 'vbox',
defaults: {
flex: 1,
width: '100%',
padding: 10,
defaults: {
flex: 1,
height: '100%',
margin: 10
}
},
items:[{
xtype: 'panel',
layout: 'hbox',
items:[
{xtype:'button',text:'按钮1'},
{xtype:'button',text:'按钮2'},
{xtype:'button',text:'按钮3'}
]
},{
xtype: 'panel',
layout: 'hbox',
items:[
{xtype:'button',text:'按钮4'},
{xtype:'button',text:'按钮5'},
{xtype:'button',text:'按钮6'}
]
},{
xtype: 'panel',
layout: 'hbox',
items:[
{xtype:'button',text:'按钮7'},
{xtype:'button',text:'按钮8'},
{xtype:'button',text:'按钮9'}
]
}]
});
}
});
/* 传统的方式 */ // setContentView(R.layout.main); /* inflater方式 */ LayoutInflater inflater = LayoutInflater.from(Inflate.this);// 生成inflater对象 LinearLayout mainFrame = (LinearLayout) inflater.inflate(R.layout.main,null);// 找到窗体的布局文件 LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); this.addContentView(mainFrame, params);
通俗的说,inflate就相当于将一个xml中定义的布局找出来.
因为在一个Activity里如果直接用findViewById()的话,对应的是setConentView()的那个layout里的组件.
因此如果你的Activity里如果用到别的layout,比如对话框上的layout,你还要设置对话框上的layout里的组件(像图片ImageView,文字TextView)上的内容,你就必须用inflate()先将对话框上的layout找出来,然后再用这个layout对象去找到它上面的组件,如:
Viewview=View.inflate(this,R.layout.dialog_layout,null);
TextViewdialogTV=(TextView)view.findViewById(R.id.dialog_tv);
dialogTV.setText("abcd");
如果组件R.id.dialog_tv是对话框上的组件,而你直接用this.findViewById(R.id.dialog_tv)肯定会报错.
三种方式可以生成LayoutInflater:
LayoutInflaterinflater=LayoutInflater.from(this); LayoutInflaterinflater=getLayoutInflater(); LayoutInflaterinflater=(LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
然后调用inflate方法将xml布局文件转成View
publicViewinflate(intresource,ViewGrouproot,booleanattachToRoot)
在View类中,也有inflate方法
publicstaticViewinflate(Contextcontext,intresource,ViewGrouproot)
举个例子:通过Inflater加载窗体布局文件