Android中小细节;
1.android:screenOrientation="portrait";
当在AndroidManifest.xml文件中定义了android:screenOrientation="portrait",就表示当我们切换横竖屏的时候,屏幕的内容始终以竖屏显示,
而不会根据屏幕的方向来显示内容。
2.dimens.xml 定义尺寸
3.在AndroidManifest.xml中隐藏标题栏,给整个程序设置主题
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar">
4.gravity和layout_gravity的区别
android:gravity 属性是对该view中内容的限定.比如一个button 上面的text. 你可以设置该text 相对于view的靠左,靠右等位置.
android:layout_gravity 是用来设置该view相对与父view的位置.比如一个button 在linearlayout里,你想把该button放在linearlayout里靠左、
靠右等位置就可以通过该属性设置
5.digits限制输入的字符
android:digits="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
6.tools:context=".MainActivity"的作用
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEEEE0"
tools:context=".MainActivity">
该页面使用和mianactivity一样的主题样式
7.pdlogin.setCancelable(false)的作用
pdlogin.setCancelable(false);为false时按返回键不能退出,默认为true,可以退出
8.动态设置控件的长宽高
mImageView = (ImageView) rl.findViewById(R.id.img1);
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams)mImageView.getLayoutParams();
lParams.width=50;
lParams.height=70;
mImageView.setLayoutParams(lParams);
9.动态获取控件的真实宽高
int w = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
mRadioButton1.measure(w, h);
int height =mRadioButton1.getMeasuredHeight();
int width =mRadioButton1.getMeasuredWidth();
10.启动activity时不自动弹出软键盘
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
11.ViewSwitcher的用法
ViewSwitcher 代表了视图切换组件, 本身继承了FrameLayout ,可以将多个View叠在一起 ,每次只显示一个组件.
当程序控制从一个View切换到另个View时,ViewSwitcher 支持指定动画效果.为了给ViewSwitcher 添加多个组件,
一般通过ViewSwitcher 的setFactory 方法设置ViewFactory ,并由ViewFactory为之创建View 即可.