A. android开发横竖屏问题
Android横屏竖屏设置
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置成全屏模式
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE););//强制为横屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏
我做的东西里面还用到了去掉标题栏。
我也贴出来
requestWindowFeature(Window.FEATURE_NO_TITLE);
垂直居中:
android:layout_centerVertical="true"
水平居中:
android:layout_centerHorizontal="true"
1.hideStatusbarAndTitlebar()隐藏statusbar和titlebar.
private void hideStatusbarAndTitlebar() {
final Window win = getWindow();
// No Statusbar
win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// No Titlebar
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
2.设置屏幕显示模式ScreenOrientation.
在activity里设置android:screenOrientation的值。
android:screenOrientation的属性有以下值:
unspecified(默 认值,由系统判断状态自动切换),The default value. The system chooses the orientation. The policy it uses, and therefore the choices made in specific contexts, may differ from device to device.
landscape,横屏
portrait,竖屏
user(用户当前设置的orientation值),The user's current preferred orientation.
behind(下一个要显示的Activity的orientation值),The same orientation as the activity that's immediately beneath it in the activity stack.
sensor(传 感器的方向),The orientation determined by a physical orientation sensor. The orientation of the display depends on how the user is holding the device; it changes when the user rotates the device.
nosensor(不 使用传感器,这个效果差不多等于unspecified).An orientation determined without reference to a physical orientation sensor. The sensor is ignored, so the display will not rotate based on how the user moves the device. Except for this distinction, the system chooses the orientation using the same policy as for the "unspecified" setting.
3.水平/垂直居中的方法.
设置parent的android:gravity为"center"。
4.获得当前屏幕宽高的方法.
Display display = getWindowManager().getDefaultDisplay();
Config.screenWidth = display.getWidth();
Config.screenHeight = display.getHeight();
B. android:layout_alignParentLeft="true"是什么意思
该行代码的总体含义为:
某控件里有该代码.某空间相对于父控件左对齐;
android:layout_alignParentLeft="true"
align为对齐方式; parent为父控件 left为左;
C. android如何实现textview水平垂直居中
1、方法:设置textview的属性android:layout_gravity="center"
2、补充:
(1)android:layout_gravity:View组件相对于Container的对齐方式。center表示将对象横纵居中,不改变其大小。
(2)属性可选的值还有:top、bottom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、fill、clip_vertical。
3、android
(1)Android是一种基于Linux的自由及开放源代码的操谨慧作系统,主要使用于祥粗答移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。Android操凳猜作系统最初由Andy Rubin开发,主要支持手机。2005年8月由Google收购注资。
(2)2007年11月,Google与84家硬件制造商、软件开发商及电信营运商组建开放手机联盟共同研发改良Android系统。随后Google以Apache开源许可证的授权方式,发布了Android的源代码。第一部Android智能手机发布于2008年10月。Android逐渐扩展到平板电脑及其他领域上,如电视、数码相机、游戏机等。2011年第一季度,Android在全球的市场份额首次超过塞班系统,跃居全球第一。
4、textview:textView是用来显示字符串的组件,在手机上就是显示一块文本的区域。
D. android:gravity="center_vertical"
android:gravity="center_vertical" 这个的意思是指 限定它里面的内容要垂直居中显示。
android:layout_gravity="center_vertical",这个是指它的位置是相对于它父亲的垂直居中。
比如:
//第一种:里面的内容都要垂直居中显示,是由父类限定子控件的位置,每个子控件都要满足这个条件。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical" //这个指里面的子内容要垂直居中显示
>
<TextView 这个 就会垂直居中显示
android:layout_width="wrap_context"
android:layout_height="wrap_context"/>
/>
</LinearLayout>
//第二种:是子控件自己去排位置,每个控件可以设置不同的
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="wrap_context"
android:layout_height="wrap_context"
android:layout_gravity="center_vertical" //这个就是让他相对于父亲的垂直中间显示。
/>
</LinearLayout>
E. 在android中如何让布局居中
两种方法:
图形化设计界面中:选中要居中的组件。在右边的“属性栏”(前提是你没有把它隐藏掉)中的Gravity一栏选择center_vertical或者center_horizontal或者center。分别表示在父布局中垂直居中、水平居中、中心。
xml代码界面当中:android:layout_gravity="center_vertical或center_horizontal或center"