一、登录界面
EditText
(1)android:hint=""设置默认提示信息
(2)android:singleLine="true" 设置单行输入,一旦设置为true,则文字不会自动换行。
(3)android:inputType=“” 指定输入法的类型,int类型,可以用|选择多个。取值可以参考:android.text.InputType类。取值包括:text,
textUri, phone,number。
(4)android:maxLength="2"设置输入的最大长度为2
(5)android:imeOptions=“actionDone”设置键盘Enter键的图标以及功能
Edittext.setOnEditorActionListener(newTextView.OnEditorActionListener() {
public booleanonEditorAction(TextView textView,inti, KeyEvent keyEvent) {
if(i == EditorInfo.IME_ACTION_DONE) {
return true;
}
return false;
}});
常见变量:
(1)actionUnspecified未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED效果
(2)actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE效果
(3)actionGo去往,对应常量EditorInfo.IME_ACTION_GO 效果
(4)actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH效果
(5)actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND效果
(6)actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT效果
(7)actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE效果
更多属性:http://www.cnblogs.com/weixing/p/3257058.html
键盘的显示与隐藏
finalInputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//获取焦点时候显示键盘
etMobileAutocode.setOnClickListener(newView.OnClickListener() {
@Override
public voidonClick(View v) {
if(!imm.isActive()){
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);//没有显示则显示
}}});
//对输入法进行监听 当点击确认按钮时隐藏键盘
etMobileAutocode.setOnEditorActionListener(newTextView.OnEditorActionListener() {
@Override
public booleanonEditorAction(TextView v,intactionId, KeyEvent event) {
if(actionId == EditorInfo.IME_ACTION_DONE){
booleanisOpen =imm.isActive();
if(isOpen) {
imm.hideSoftInputFromWindow(etMobileAutocode.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
return true;
}
return false;
}});
更多详情:http://www.cnblogs.com/yejiurui/archive/2013/01/02/2841945.html
二、首界面
1、include、merge、ViewStub
include重用布局文件
(1)可以通过指定ID来分辨不同的界面
include_2=findViewById(R.id.include_2);
include_2.findViewById(R.id.content_2);
(2)可以在这个标签中继续设定width、hight、padding、margin等属性
merge减少层级,优化UI
多用于替换FrameLayout或者当一个布局包含另一个时,标签消除视图层次结构中多余的视图组。只能用于根布局
ViewStub需要该控件是再让他显示出来,方便控件的显示和隐藏
各种不常用的布局想进度条、显示错误消息等可以使用标签,以减少内存使用量,加快渲染速度。
更多属性:http://blog.youkuaiyun.com/xyz_lmn/article/details/14524567
2、DrawerLayout
(1)xml文件中drawerlayout标签中要包含两个部分的布局:侧滑菜单栏和主要展示内容栏
(2)侧滑栏要有一个属性:android:layout_gravity="start"
(3)设置去除阴影部分DrawerLayout.setScrimColor(Color.TRANSPARENT);
(4)设置该控件打开关闭:
if(homepageDrawerLayout.isDrawerVisible(GravityCompat.START)) {
homepageDrawerLayout.closeDrawer(GravityCompat.START);
}else{
homepageDrawerLayout.openDrawer(GravityCompat.START);
}
(5)对该控件的状态的监听通过Drawerlayout.addDrawerListener
(6)设置打开抽屉的动画主要是nineoldandroids
View mContent =homepageDrawerLayout.getChildAt(0);
floatscale =1- slideOffset;
floatrightScale =0.8f+ scale *0.2f;
floatleftScale =1-0.3f* scale;
//缩放
ViewHelper.setScaleX(drawerView, leftScale);
ViewHelper.setScaleY(drawerView, leftScale);
ViewHelper.setAlpha(drawerView,0.6f+0.4f* (1- scale));
ViewHelper.setTranslationX(mContent,
drawerView.getMeasuredWidth() * (1- scale));
ViewHelper.setPivotX(mContent,0);
ViewHelper.setPivotY(mContent,
mContent.getMeasuredHeight() /2);
mContent.invalidate();
更多属性:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0303/2522.html
3.LinearLayout设置layout_gravity失效的问题
使用LinearLayout布局,其中的子View设置android:layout_gravity="bottom"属性后不起作用,原因是:
当LinearLayout设置android:orientation="vertical" 时, 只有水平方向的left,right,center_horizontal设置起作用,垂直方向的设置不起作用。
当LinearLayout设置android:orientation="horizontal" 时, 只有垂直方向的top,bottom,center_vertical设置才起作用,水平方向的设置不起作用。