首页 文章 精选 留言 我的

精选列表

搜索[基础],共10000篇文章
优秀的个人博客,低调大师

【Android 基础】EditText的属性介绍

EditText继承TextView,所以EditText具有TextView的属性特点,下面主要介绍一些EditText的特有的输入法的属性特点 android:layout_gravity="center_vertical":设置控件显示的位置:默认top,这里居中显示,还有bottom android:hin :Text为空时显示的文字提示信息,可通过textColorHint设置提示信息的颜色。 android:singleLine :设置单行输入,一旦设置为 true ,则文字不会自动换行。 android:gray="top" :多行中指针在第一行第一位置 et.setSelection(et.length()); :调整光标到最后一行 android:autoText :自动拼写帮助。这里单独设置是没有效果的,可能需要其他输入法辅助才行 android:capitalize :设置英文字母大写类型。设置如下值:sentences仅第一个字母大写;words每一个单词首字母大小,用空格区分单词;characters每一个英文字母都大写。 android:digits :设置允许输入哪些字符。如“1234567890.+-*/%\n()” android:singleLine :是否单行或者多行,回车是离开文本框还是文本框增加新行 android:numeric :如果被设置,该TextView接收数字输入。有如下值设置:integer正整数、signed带符号整数、decimal带小数点浮点数。 android:inputType:设置文本的类型 android:password :密码,以小点”.”显示文本 android:phoneNumber :设置为电话号码的输入方式。 android:editable :设置是否可编辑。仍然可以获取光标,但是无法输入。 android:autoLink=”all” :设置文本超链接样式当点击网址时,跳向该网址 android:textColor = "#ff8c00" :字体颜色 android:textStyle="bold" :字体, bold, italic, bolditalic android:textAlign="center" : EditText 没有这个属性,但 TextView 有 android:textColorHighlight="#cccccc" :被选中文字的底色,默认为蓝色 android:textColorHint="#ffff00" :设置提示信息文字的颜色,默认为灰色 android:textScaleX="1.5" :控制字与字之间的间距 android:typeface="monospace" :字型, normal, sans, serif, monospace android:background="@null" :空间背景,这里没有,指透明 android:layout_weight="1" :权重在控制控件显示的大小时蛮有用的。 android:textAppearance="?android:attr/textAppearanceLargeInverse" :文字外观,这里引用的是系统自带的一个外观,?表示系统是否有这种外观,否则使用默认的外观。 本文转自叶超Luka博客园博客,原文链接:http://www.cnblogs.com/yc-755909659/archive/2012/08/18/2645426.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android RenderScript 的使用基础篇

准备上4.0项目,最近接触API 的时候看到了RenderScript 。通过运行google 那几个项目发现这个真是一个非常不错的API,但是google 所提供的文档非常少,有助于了解计算机图形计算,虽然我们做应用编程的不一定要涉及这块,但涉猎一下总是不错的。 RenderScript 是Android 平台上的一种类C脚本语言。要在我们程序上实现RenderScript 渲染功能,最少需要实现的几个功能如下,以一个Hello Wold 为例: helloworld.rs实现RenderScript 的代码 RenderScriptRS.java 一个辅助类,简化操作RenderScript (非必要) RenderScriptView.java 一个继承于RSSurfaceView的类,用于显示RenderScript 的渲染或者用来处理用户的触摸等视图 RenderScriptHelloWorldActivity.java 这个不用多说,Android 应用程序的界面类 当创建一个RenderScript 的项目的时候,必须在包名下创建一个以rs为后缀的文件(位于我们Activity 同包名下),如本篇文章使用的helloworld.rs文件. #pragmaversion(1) #pragmarsjava_package_name(com.xuzhi.rs.helloworld) #include"rs_graphics.rsh" intgTouchX ;intgTouchY ; voidinit(){ gTouchX=50.0f ;gTouchY=50.0f ;} //applicationmain introot(void){ rsgClearColor(0.0f,1.0f,0.0f,0.0f) ;//颜色更改为no red,full green,no blue,no opacity ,的RGBA值rsgFontColor(1.0f,0.0f,1.0f,1.0f) ;//设置字体颜色rsgDrawText("myfirstrenderscriptapplication",gTouchX,gTouchY) ;//根据应用传上来的x,y 将字画在屏幕对应的坐标上rsDebug("======myrenderscriptdebug========",rsUptimeMillis()) ;//打印日志return 20 ; } 注解: #pragma:简单的可以理解告诉或者通知编译器编译这个文件时需要的参数或者指定编译的版本等,跟编译器有关。 void init():这个函数作一些初始化动作 int root(viod):程序入口,根据返回值(ms)作刷新。比如上面写的20相当于每20毫秒刷新一次。 root 函数下rsgClearColor,rsgFontColor,rsgDrawText都位于rs_graphics.rsh头文件下。 rsDebug是打印日志函数,位于rs_core.rsh头文件。 在上面的代码中,日志将己每20毫秒打印一次这样的日志:03-01 11:09:18.289: D/RenderScript(1838): ======my renderscript debug======== 600462 0x9298e rsUptimeMillis则定义在rs_time.rsh头文件中。 目前有关于RenderScript调用的函数位于我们SDK目录下(platforms/android-*[目前11-15]/renderscript/include)目录里面的头文件中。 好了,rs文件己经编写完成,接着往下走。 下一步,为了方便调用RenderScript 这里创建了一个辅助类,RenderScriptRS.java。 /** *RenderScripthelp * @author terry * */ public classRenderScriptRS{ privateRenderScriptGLmRS; privateScriptC_hellowoldmScript; publicRenderScriptRS(RenderScriptGLrs,Resourcesresource){ // TODOAuto-generatedconstructorstub mRS=rs; mScript= newScriptC_helloworld(mRS,resource,R.raw.hellowold); mRS.bindRootScript(mScript); //绑定脚本 } /** *传入坐标 * @param x * @param y */ public voidonActionDown( intx, inty){ mScript.set_gTouchX(x); mScript.set_gTouchY(y); } } 目前我们所做的一切都是要使用到的RenderScriptGL(RenderScript 图形的衍生),实例化RenderScriptGL并绑定脚本。如果你的开发ADT高于或者是1.5的话Eclipse 会根据你的rs文件生成ScriptC_你的rs文件为名的java类。如上面代码的ScriptC_helloworld一样,并且在资源目录res/raw生成一个.bc的文件,在实例化ScriptC_hellowold会需要传进去。 下一步,创建RenderScriptView.java,让其可以显示在界面上。 importandroid.content.Context; importandroid.renderscript.RSSurfaceView; importandroid.renderscript.RenderScriptGL; importandroid.renderscript.RenderScriptGL.SurfaceConfig; importandroid.view.MotionEvent; public classRenderScriptView extendsRSSurfaceView{ privateRenderScriptGLmRS; privateRenderScriptRSmRender; publicRenderScriptView(Contextcontext){ super(context); // TODOAuto-generatedconstructorstub initRenderScript(); } /** *初始化RenderScriptRS */ private voidinitRenderScript(){ if(mRS== null){ RenderScriptGL.SurfaceConfigconfig= newSurfaceConfig(); mRS=createRenderScriptGL(config); mRender= newRenderScriptRS(mRS,getResources()); } } @Override protected voidonDetachedFromWindow(){ // Handlethesystemeventandcleanup mRender= null; if(mRS!= null){ mRS= null; destroyRenderScriptGL(); } } @Override protected voidonAttachedToWindow(){ // TODOAuto-generatedmethodstub super.onAttachedToWindow(); initRenderScript(); } @Override public booleanonTouchEvent(MotionEventevent){ // TODOAuto-generatedmethodstub /** *传入点击坐标 */ if(event.getAction()==MotionEvent.ACTION_DOWN){ mRender.onActionDown(( int)event.getX(),( int)event.getY()); return true; } return false; } } RSSurfaceView扩展自SurfaceView,用来显示这些需要渲染的图形界面。 上述代码的initRenderScript方法,如果RenderScriptGL 未实例化,就需要创建一个SurfaceConfig(这是用来控制深度的颜色,深度缓冲区等等,这里使用默认),并且让它实现自身的onTouchEvent事件,传入x,y坐标轴进入RenderScript,改变文本显示的位置(跟随鼠标的点击点变化)。 最后的界面只需要让它显示出来即可: public classRenderScriptHelloWorldActivity extendsActivity{ /** Calledwhentheactivityisfirstcreated. */ @Override public voidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView( newRenderScriptView( this)); } } 这一系列的步骤可以用一张图来做说明,详细的规划了RenderScript 的图形概述: 这是一个简单的DEMO,介绍了RenderScript 使用的一些基本步骤,详细的使用后面会慢慢提到。最后通过上面的代码可以看到的运行效果如下: 另外,后文还会提供一些详细的文档和例子。比如: rs_graphics rs_core rs_math rs_time 上面这四个的头文件的API。 代码可以在Android 4.0中找到,RenderScript->Helloworld。 注:模拟器无法运行。 本文转自 terry_龙 51CTO博客,原文链接:http://blog.51cto.com/terryblog/801089,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android基础:shape的基本用法

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 边角的圆弧半径 --> <corners android:radius="9dp" /> <!-- 实心填充 --> <solid android:color="#00000000" /> <!-- 描边:一般大小都是1dp --> <stroke android:width="1dp" android:color="#ff000000" /> <!-- 四周留出来的空白,和xml文件中的pad效果一样,对内起作用 --> <padding android:bottom="30dp" android:left="20dp" android:right="30dp" android:top="20dp" /> <!-- 背景颜色渐变 --> <gradient android:angle="90" android:endColor="#ff00ff00" android:startColor="#ff0000ff" /> </shape> shape总体说来可以看做是使一张图片,放在drawable目录下,可以单独使用,也可以和selector一起使用,主要用户处理图片的圆角,点击变色的变化。可以单独写comm_shape.xml,press_shape.xml(文件名是随便取的), 然后结合selector使用,如果熟练的话可以直接在selector中直接写,那样看起来文件不是那么多。注意上面的代码中,实心solid和渐变gradient一般不会一起使用。 本文转自demoblog博客园博客,原文链接http://www.cnblogs.com/0616--ataozhijia/archive/2012/10/31/2747284.html如需转载请自行联系原作者 demoblog

优秀的个人博客,低调大师

LNMP基础架构介绍与安装

1、LNMP架构介绍 LNMP==Linux+Nginx+Mysql+PHP nginx:省资源,省cpu,所以在高并发时能够处理更多的请求,高端能达到3万到5万的并发量。 nginx和LAMP不同的是,提供web服务的是Nginx 并且php是作为一个独立服务存在的,这个服务叫做php-fpm Nginx直接处理静态请求,动态请求会转发给php-fpm 在当前互联网环境下,一般高端的服务前端都采用nginx作为web前端,而更多的都是采用lnmp架构,真正的后端服务器才会采用apache. 为什么这么做,要取决于nginx和apache两者之间的优缺性.: nginx与apache相比有以下优势:在性能上,nginx占用很少的系统资源,能支持更多的并发链接,达到更高的访问率;在功能上,Nginx是优秀的代理服务器和负载均衡器;在安装配置上,简单灵活。 nginx模块基本都是静态编译,同时对Fast-CGI支持比较好.在处理链接上,nginx支持epoll,而且体积小一般只有几百K。 Nginx的优点有以下几点: 1.作为Web服务器,nginx处理静态文件、索引文件以及自动索引效率非常高。 2.作为代理服务器,Nginx可以实现无缓存的反向代理加速,提高网站运行速度。 3.作为负载均衡服务器,Nginx既可以在内部直接支持Rails和PHP,也可以支持HTTP代理服务器,对外进行服务。同时支持简单的容错和利用算法进行负载均衡。 4.在性能方面,Nginx是专门为性能优化而开发的,在实现上非常注重效率。它采用内核Poll模型,可以支持更多的并发连接,最大可以支持对50 000个并发连接数的响应,而且占用很低的内存资源。 5.在稳定性方面,Nginx采取了分阶段资源分配技术,使得对CPU与内存的占用率非常低。Nginx官方表示Nginx保持10 000个没有活动的连接,这些连接只占2.5M内存,因此,类似DOS这样的攻击对Nginx来说基本上是没有任何作用的。 6.在高可用性方面,Nginx支持热部署,启动速度特别迅速,因此可以在不间断服务的情况下,对软件版本或者配置进行升级,即使运行数月也无需重新启动,几乎可以做到7×24小时的不间断运行。 2、mysql安装 安装mysql的配置,其实在做LAMP的时候已经做过了,一模一样的编译配置。http://blog.51cto.com/chy940405/2047288(有需要的可以看看这篇) 3、php安装总结 和LAMP安装PHP方法有差别,需要开启php-fpm服务 [root@chy php-5.6.30]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz [root@chy php-5.6.30]# tar -zxvf php-5.6.30.tar.gz [root@chy01 php-5.6.30]# useradd -s /sbin/nologin php-fpm (增加php-fpm用户) [root@chy01 php-5.6.30]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl (编译参数如上,如下是详解参数 ./configure --prefix=/usr/local/php-fpm(php路径) --with-config-file-path=/usr/local/php-fpm/etc(php配置文件路径) --enable-fpm(启动服务必须的参数) --with-fpm-user=php-fpm(指定php的用户) --with-fpm-group=php-fpm(指定phpd 的组) --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl 报错信息1:configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/ 解决方法:[root@chy01 php-5.6.30]# yum install -y libcurl-devel 然后再次编译时:编译成功 [root@chy01 php-5.6.30]# echo $? 0 [root@chy01 php-5.6.30]# make && make install (然后make 与make install) [root@chy01 php-5.6.30]# echo $? 0 (make 成功) php-fpm简单介绍 [root@chy01 php-5.6.30]# ls /usr/local/php-fpm/sbin/ php-fpm 其中(php-fpm是php-fpm的启动文件) [root@chy01 php-5.6.30]# ls /usr/local/php-fpm/var/log/ (查看日志的启动文件) [root@chy01 php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -i [root@chy01 php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -m (查看php的模块) [root@chy01 php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -t [10-Aug-2017 01:41:12] ERROR: failed to open configuration file '/usr/local/php-fpm/etc/php-fpm.conf': No such file or directory (2) [10-Aug-2017 01:41:12] ERROR: failed to load configuration file '/usr/local/php-fpm/etc/php-fpm.conf' [10-Aug-2017 01:41:12] ERROR: FPM initialization failed (-t测试php-fpm的配置的语法是否正确) [root@chy01 php-5.6.30]# cp php.ini-production /usr/local/php-fpm/etc/php.ini (cp php的线上的配置文件到/usr/local/php-fpm/etc/php.ini下去) [root@chy01 php-5.6.30]# cd /usr/local/php-fpm/etc/ [root@chy01 etc]# ls pear.conf php-fpm.conf.default php.ini [root@chy01 etc]# vim php-fpm.conf (创建php-fpm.conf,增加如下配置) [global] pid = /usr/local/php-fpm/var/run/php-fpm.pid error_log = /usr/local/php-fpm/var/log/php-fpm.log [www] listen = /tmp/php-fcgi.sock listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 (配置文件含义如下:[global](定义全局参数) pid = /usr/local/php-fpm/var/run/php-fpm.pid (定义pid) error_log = /usr/local/php-fpm/var/log/php-fpm.log [www] (服务的名称) listen = /tmp/php-fcgi.sock(监听的sock) #listen =127.0.0.1:9000 (这个是监听的ip地址) listen.mode = 666(这个是如果监听的是sock此项才会生效,则不会生效) user = php-fpm(用来定义用户) group = php-fpm pm = dynamic (如下是关于进程的信息) pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 [root@chy01 etc]# cd /usr/local/src/php-5.6.30 (进入到php的源码包里) [root@chy01 php-5.6.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm (cp配置文件到/etc/init.d/php-fpm 下) [root@chy01 php-5.6.30]# chmod 755 /etc/init.d/php-fpm (更改配置权限为755) [root@chy01 php-5.6.30]# chkconfig --add php-fpm [root@chy01 php-5.6.30]# chkconfig --list 注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。 欲查看对特定 target 启用的服务请执行 'systemctl list-dependencies [target]'。 apache2 0:关 1:关 2:关 3:开 4:关 5:开 6:关 mysqld 0:关 1:关 2:开 3:开 4:开 5:开 6:关 netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关 network 0:关 1:关 2:开 3:开 4:开 5:开 6:关 php-fpm 0:关 1:关 2:开 3:开 4:开 5:开 6:关 (增加到开机启动) [root@chy01 php-5.6.30]# /etc/init.d/php-fpm start Starting php-fpm done (启动服务) [root@chy01 php-5.6.30]# ps aux |grep php-fpm root 125159 0.0 0.3 226640 4948 ? Ss 02:13 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 125160 0.0 0.3 226640 4712 ? S 02:13 0:00 php-fpm: pool www php-fpm 125161 0.0 0.3 226640 4712 ? S 02:13 0:00 php-fpm: pool www php-fpm 125162 0.0 0.3 226640 4712 ? S 02:13 0:00 php-fpm: pool www php-fpm 125163 0.0 0.3 226640 4712 ? S 02:13 0:00 php-fpm: pool www php-fpm 125164 0.0 0.3 226640 4716 ? S 02:13 0:00 php-fpm: pool www php-fpm 125165 0.0 0.3 226640 4720 ? S 02:13 0:00 php-fpm: pool www php-fpm 125166 0.0 0.3 226640 4720 ? S 02:13 0:00 php-fpm: pool www php-fpm 125167 0.0 0.3 226640 4720 ? S 02:13 0:00 php-fpm: pool www php-fpm 125168 0.0 0.3 226640 4720 ? S 02:13 0:00 php-fpm: pool www php-fpm 125169 0.0 0.3 226640 4720 ? S 02:13 0:00 php-fpm: pool www php-fpm 125170 0.0 0.3 226640 4720 ? S 02:13 0:00 php-fpm: pool www php-fpm 125171 0.0 0.3 226640 4720 ? S 02:13 0:00 php-fpm: pool www php-fpm 125172 0.0 0.3 226640 4720 ? S 02:13 0:00 php-fpm: pool www php-fpm 125173 0.0 0.3 226640 4720 ? S 02:13 0:00 php-fpm: pool www php-fpm 125174 0.0 0.3 226640 4720 ? S 02:13 0:00 php-fpm: pool www php-fpm 125175 0.0 0.3 226640 4720 ? S 02:13 0:00 php-fpm: pool www php-fpm 125176 0.0 0.3 226640 4720 ? S 02:13 0:00 php-fpm: pool www php-fpm 125177 0.0 0.3 226640 4720 ? S 02:13 0:00 php-fpm: pool www php-fpm 125178 0.0 0.3 226640 4720 ? S 02:13 0:00 php-fpm: pool www php-fpm 125179 0.0 0.3 226640 4720 ? S 02:13 0:00 php-fpm: pool www root 125220 0.0 0.0 112664 976 pts/0 R+ 02:15 0:00 grep --color=auto php-fpm [root@chy01 php-5.6.30]# ls -l /tmp/php-fcgi.sock srw-rw-rw- 1 root root 0 8月 10 02:13 /tmp/php-fcgi.sock 4nginx介绍与安装 nginx官网http://nginx.org Nginx应用场景:web服务、反向代理、负载均衡 Nginx著名分支,淘宝基于Nginx开发的Tengine,使用上和Nginx一致,服务名,配置文件名都一样,和Nginx的最大区别在于Tenging增加了一些定制化模块,在安全限速方面表现突出,另外它支持对js,css合并 [root@chy01 src]# wget http://nginx.org/download/nginx-1.12.1.tar.gz (下载nginx安装包) [root@chy01 src]# tar zxvf nginx-1.12.1.tar.gz (解压) [root@chy01 src]./configure --prefix=/usr/local/nginx [root@chy01 src]# cd nginx-1.12.1 (进入到此目录下开始编译) [root@chy01 nginx-1.12.1]# echo $? 0 [root@chy01 nginx-1.12.1]# make && make install [root@chy01 nginx-1.12.1]# echo $? 0 (编译成功) [root@chy01 nginx-1.12.1]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful (-t检查配置文件语法是否错误) [root@chy01 nginx-1.12.1]# vim /etc/init.d/nginx (在启动配置文件中增加如下内容) #!/bin/bash # chkconfig: - 30 21 # description: http service. # Source Function Library . /etc/init.d/functions # Nginx Settings NGINX_SBIN="/usr/local/nginx/sbin/nginx" NGINX_CONF="/usr/local/nginx/conf/nginx.conf" NGINX_PID="/usr/local/nginx/logs/nginx.pid" RETVAL=0 prog="Nginx" start() { echo -n $"Starting $prog: " mkdir -p /dev/shm/nginx_temp daemon $NGINX_SBIN -c $NGINX_CONF RETVAL=$? echo return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p $NGINX_PID $NGINX_SBIN -TERM rm -rf /dev/shm/nginx_temp RETVAL=$? echo return $RETVAL } reload() { echo -n $"Reloading $prog: " killproc -p $NGINX_PID $NGINX_SBIN -HUP RETVAL=$? echo return $RETVAL } restart() { stop start } configtest() { $NGINX_SBIN -c $NGINX_CONF -t return 0 } case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo $"Usage: $0 {start|stop|reload|restart|configtest}" RETVAL=1 esac exit $RETVAL [root@chy01 nginx-1.12.1]# chmod 755 /etc/init.d/nginx (增加nginx权限) [root@chy01 nginx-1.12.1]# chkconfig --add nginx (将nginx设置为开机自启) [root@chy01 nginx-1.12.1]# cd /usr/local/nginx/conf/ (配置nginx的配置文件,需要先下一个模板) [root@chy01 conf]# mv nginx.conf nginx.conf.1 (因nginx已经有一个配置文件,需要将此配置文件cp并且重新更改一个自己的配置文件) [root@chy01 conf]# vim nginx.conf (配置nginx的配置文件) user nobody nobody; worker_processes 2; error_log /usr/local/nginx/logs/nginx_error.log crit; pid /usr/local/nginx/logs/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 6000; } http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 3526; server_names_hash_max_size 4096; log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' ' $host "$request_uri" $status' ' "$http_referer" "$http_user_agent"'; sendfile on; tcp_nopush on; keepalive_timeout 30; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; connection_pool_size 256; client_header_buffer_size 1k; large_client_header_buffers 8 4k; request_pool_size 4k; output_buffers 4 32k; postpone_output 1460; client_max_body_size 10m; client_body_buffer_size 256k; client_body_temp_path /usr/local/nginx/client_body_temp; proxy_temp_path /usr/local/nginx/proxy_temp; fastcgi_temp_path /usr/local/nginx/fastcgi_temp; fastcgi_intercept_errors on; tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 4 8k; gzip_comp_level 5; gzip_http_version 1.1; gzip_types text/plain application/x-javascript text/css text/htm application/xml; server { listen 80; server_name localhost; index index.html index.htm index.php; root /usr/local/nginx/html; location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/tmp/php-fcgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; } } } 如下是配置文件的简单介绍: user nobody nobody; (定义的nginx的用户) worker_processes 2;(定义子进程有几个) error_log /usr/local/nginx/logs/nginx_error.log crit; (定义错误日志) pid /usr/local/nginx/logs/nginx.pid; worker_rlimit_nofile 51200;(定义nginx最多能打开多少个文件) events { use epoll; worker_connections 6000;(进程有多少个连接) } http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 3526; server_names_hash_max_size 4096; log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' ' $host "$request_uri" $status' ' "$http_referer" "$http_user_agent"'; sendfile on; tcp_nopush on; keepalive_timeout 30; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; connection_pool_size 256; client_header_buffer_size 1k; large_client_header_buffers 8 4k; request_pool_size 4k; output_buffers 4 32k; postpone_output 1460; client_max_body_size 10m; client_body_buffer_size 256k; client_body_temp_path /usr/local/nginx/client_body_temp; proxy_temp_path /usr/local/nginx/proxy_temp; fastcgi_temp_path /usr/local/nginx/fastcgi_temp; fastcgi_intercept_errors on; tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 4 8k; gzip_comp_level 5; gzip_http_version 1.1; gzip_types text/plain application/x-javascript text/css text/htm application/xml; server { listen 80; server_name localhost; index index.html index.htm index.php; root /usr/local/nginx/html; location ~ \.php$ (配置解析Php) { include fastcgi_params; fastcgi_pass unix:/tmp/php-fcgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; } } } [root@chy01 conf]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful (查看nginx配置文件是否有错) [root@chy01 conf]# /etc/init.d/nginx start(这里报了一个错误) Starting nginx (via systemctl): Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. [失败] (根据提示查错误,[root@chy01 conf]# systemctl status nginx.service ● nginx.service - SYSV: http service. Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled) Active: failed (Result: exit-code) since 五 2017-08-11 00:23:23 CST; 36s ago Docs: man:systemd-sysv-generator(8) Process: 5613 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=1/FAILURE) 8月 11 00:23:21 chy01 nginx[5613]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 8月 11 00:23:21 chy01 nginx[5613]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 8月 11 00:23:22 chy01 nginx[5613]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 8月 11 00:23:22 chy01 nginx[5613]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 8月 11 00:23:23 chy01 nginx[5613]: nginx: [emerg] still could not bind() 8月 11 00:23:23 chy01 nginx[5613]: [失败] 8月 11 00:23:23 chy01 systemd[1]: nginx.service: control process exited, code=exited status=1 8月 11 00:23:23 chy01 systemd[1]: Failed to start SYSV: http service.. 8月 11 00:23:23 chy01 systemd[1]: Unit nginx.service entered failed state. 8月 11 00:23:23 chy01 systemd[1]: nginx.service failed. (可以看到提示错误nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 提示的意思为80端口被使用) [root@chy01 conf]# /usr/local/apache2.4/bin/apachectl stop (将http关闭) [root@chy01 conf]# /etc/init.d/nginx start Starting nginx (via systemctl): [ 确定 ] (在进行启动,启动成功) [root@chy01 conf]# ps aux |grep nginx root 5655 0.0 0.0 20484 628 ? Ss 00:24 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf nobody 5656 0.0 0.2 22928 3216 ? S 00:24 0:00 nginx: worker process nobody 5657 0.0 0.2 22928 3216 ? S 00:24 0:00 nginx: worker process root 5672 0.0 0.0 112664 976 pts/0 S+ 00:26 0:00 grep --color=auto nginx (可以看到子进程为root,主进程为nobody) [root@chy01 conf]# curl localhost <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> (nginx 进行测试) [root@chy01 conf]# vim /usr/local/nginx/html/1.php (创建一个php的测试文件 <?php echo "this is nginx test page"; [root@chy01 conf]# curl localhost/1.php this is nginx test page[root@chy01 conf]# (如上解析成功) 本文转自我不是瘦子51CTO博客,原文链接:http://blog.51cto.com/chy940405/2049295,如需转载请自行联系原作者

优秀的个人博客,低调大师

Linux基础之任务计划(at,crontab)

在linux系统中你可能已经发现了为什么系统常常会自动的进行一些任务?这些任务到底是谁在支配他们工作的?在linux系统如果你想要让自己设计的备份程序可以自动在某个时间点开始在系统底下运行,而不需要手动来启动它,又该如何处置呢? 这些例行的工作可能又分为一次性定时工作与循环定时工作,在系统内又是哪些服务在负责? 命令at及crontab可以解决上述问题 at:未来的某时间点执行一次某任务 crontab:用于周期性运行某任务 二者的执行结果或通过邮件发送给用户。 at命令 通过命令yum provides atd查看at的包名 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 yumprovidesatdroot@localhost Loadedplugins:fastestmirror Loadingmirrorspeedsfromcachedhostfile base /7/x86_64/filelists_db |6.7MB00:00:00 epel /x86_64/filelists_db |8.1MB00:00:00 extras /7/x86_64/filelists_db |391kB00:00:00 updates /7/x86_64/filelists_db |1.5MB00:00:00 zabbix /x86_64/filelists_db |53kB00:00:00 zabbix-non-supported /x86_64/filelists |660B00:00:00 at-3.1.13-22.el7.x86_64:Jobspoolingtools Repo:base Matchedfrom: Filename: /usr/sbin/atd at-3.1.13-22.el7.x86_64:Jobspoolingtools Repo:@base Matchedfrom: Filename: /usr/sbin/atd 常用格式:at [option] ... TIME at允许使用一套相当复杂的指定时间的方法。他能够接受在当天的hh:mm(小时:分钟)式的时间指定。假如该时间已过去,那么就放在第二天执行。当然也能够使用midnight(深夜),noon(中午),teatime(饮茶时间,一般是下午4点)等比较模糊的 词语来指定时间。用户还能够采用12小时计时制,即在时间后面加上AM(上午)或PM(下午)来说明是上午还是下午。 也能够指定命令执行的具体日期,指定格式为month day(月 日)或mm/dd/yy(月/日/年)或dd.mm.yy(日.月.年)。指定的日期必须跟在指定时间的后面。 上面介绍的都是绝对计时法,其实还能够使用相对计时法,这对于安排不久就要执行的命令是很有好处的。指定格式为:now + count time-units ,now就是当前时间,time-units是时间单位,这里能够是minutes(分钟)、hours(小时)、days(天)、weeks(星期)。count是时间的数量,究竟是几天,还是几小时,等等。 更有一种计时方法就是直接使用today(今天)、tomorrow(明天)来指定完成命令的时间。 TIME:时间格式,这里可以定义出什么时候要进行 at 这项任务的时间,格式有: HH:MM ex>04:00 在今日的 HH:MM 时刻进行,若该时刻已超过,则明天的 HH:MM 进行此任务。 HH:MM YYYY-MM-DD ex>04:00 2016-09-19 强制规定在某年某月的某一天的特殊时刻进行该项任务 HH:MM[am|pm] [Month] [Date] ex>04pm September 17 也是一样,强制在某年某月某日的某时刻进行该项任务 HH:MM[am|pm] + number [minutes|hours|days|weeks] ex>now + 5 minutes ex>04pm + 3 days 就是说,在某个时间点再加几个时间后才进行该项任务。 常用选项: -l:查看作业队列,相当于atq -f:从指定文件中读取作业任务,而不用再交互式输入 -d:删除指定的作业,相当于atrm -c:查看指定作业的具体内容 -q:指明队列 注:作业执行结果是以邮件发送给提交作业的用户 在使用at命令前,我们需要先确认at所依赖的atd进程是否启用,使用命令:ps -ef | grep atd查看,若未启用则用/etc/init.d/atd start or restart开启。 执行方式: 1)交互式,在命令输入完成后使用ctrl+d保存退出;2)输入重定向;3)at -f 文件 示例1:2分钟后使用ls命令展开/tmp目录(交互式命令输入结束后使用ctrl+d保存退出) 1 2 3 4 [root@docker~] #atnow+2minutes at> ls /tmp at><EOT> job7atSunSep1809:17:002016 命令执行结果在mail里面看 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 [root@docker~] #mail HeirloomMailversion12.57 /5/10 .Type? for help. "/var/spool/mail/root" :9messages1unread 1user@localhost. local TueJul1916:4690 /2915 "[abrt]fullcrashreport" 2docker@docker.localdThuSep811:0016 /568 "Outputfromyourjob1" 3user@localhost. local MonSep1210:31353 /15306 "[abrt]fullcrashreport" 4user@localhost. local MonSep1210:31443 /17535 "[abrt]fullcrashreport" 5rootSunSep1809:0423 /998 "Outputfromyourjob3" 6rootSunSep1809:0819 /827 "Outputfromyourjob4" 7rootSunSep1809:13275 /2986 "Outputfromyourjob5" 8rootSunSep1809:1526 /552 "Outputfromyourjob6" >U9rootSunSep1809:1718 /776 "Outputfromyourjob7" >U9rootSunSep1809:1718 /776 "Outputfromyourjob7" &9 Message9: Fromroot@docker.localdomainSunSep1809:17:012016 Return-Path:<root@docker.localdomain> X-Original-To:root Delivered-To:root@docker.localdomain Subject:Outputfromyourjob7 To:root@docker.localdomain Date:Sun,18Sep201609:17:01+0800(CST) From:root@docker.localdomain(root) Status:RO systemd-private-2c8c4ebab1524b5c9f463bd2ec8ffea7-colord.service-gyAadP systemd-private-2c8c4ebab1524b5c9f463bd2ec8ffea7-cups.service-6gB4MM systemd-private-2c8c4ebab1524b5c9f463bd2ec8ffea7-rtkit-daemon.service-25oPVw systemd-private-2c8c4ebab1524b5c9f463bd2ec8ffea7-vmtoolsd.service-sW2CqM 示例2:明天14点中,重启系统。(使用输入重定向实现) 1 2 3 4 5 6 [root@docker~] #at14:00tomorrow>>time1<<eof >reboot >eof job8atMonSep1914:00:002016 [root@docker~] #atq 8MonSep1914:00:002016aroot 示例3:删除示例2的计划任务 1 2 [root@docker~] #at-d8 [root@docker~] #atq at命令的执行权限: 配置文件/etc/at.{allow,deny}决定了允许哪些用户可以使用at命令,哪些用户不可以。 加上这两个文件后, at 的工作情况是这样的: 先找寻 /etc/at.allow 这个文件,写在这个文件中的使用者才能使用 at ,没有在这个文件中的使用者则不能使用 at (即使没有写在 at.deny 当中); 如果 /etc/at.allow 不存在,就寻找 /etc/at.deny 这个文件,若写在这个 at.deny 的使用者则不能使用 at ,而没有在这个 at.deny 文件中的使用者,就可以使用 at 命令了。 如果两个文件都不存在,那么只有 root 可以使用 at 这个命令。 透过这个说明,我们知道 /etc/at.allow 是管理较为严格的方式,而 /etc/at.deny 则较为松散 (因为帐号没有在该文件中,就能够运行 at 了)。在一般的 distributions 当中,由于假设系统上的所有用户都是可信任的, 因此系统通常会保留一个空的 /etc/at.deny 文件,意思是允许所有人使用 at 命令的意思 (您可以自行检查一下该文件)。 不过,万一你不希望有某些使用者使用 at 的话,将那个使用者的帐号写入 /etc/at.deny 即可! 一个帐号写一行。 crontab命令 通过命令yum provides crontab查看crontab命令的包名 1 2 3 4 5 6 7 8 9 10 11 yumprovides crontab root@localhost Loadedplugins:fastestmirror Loadingmirrorspeedsfromcachedhostfile cronie-1.4.11-17.el7.x86_64:Crondaemon for executingprogramsat set times Repo:base Matchedfrom: Filename: /usr/bin/crontab cronie-1.4.11-14.el7_2.1.x86_64:Crondaemon for executingprogramsat set times Repo:@anaconda Matchedfrom: Filename: /usr/bin/crontab cron来源于希腊单词chronos(意为“时间”),是linux系统下一个周期性自动执行指定任务的程序 在使用cron前,需要确认crond守护进程处于运行状态,才能保证cron的正常运行。 可以通过命令:systemctl status crond 及ps -ef | grep crond查看服务cron是否处于运行状态。 向crond提交作业的方式与at不同,它需要使用专用的配置文件,此文件有固定格式,不建议使用文本编辑器直接编辑此文件;需要使用crontab命令; cron任务分为两类: 系统cron任务:主要用于实现系统自身的维护 手动编辑/etc/crontab文件 用户cron任务:使用命令crontab /etc/crontab文件 注: 1)每一行定义一个周期性任务;共7个字段 * * * * * :定义周期性时间 username:运行任务的用户身份 command to be executed:要执行的任务 2)此处的环境变量不同于用户登陆后获得的环境,因此建议命令使用绝对路径,或定义PATH环境变量 3)执行结果邮件发送给MAILTO指定的用户(发送给运行任务的用户) 时间表示法: (1)特定值; 给定时间点有效取值范围内的值; (2)* 给定时间点上有效取值范围内的所有值; 表示“每...”; 示例: 1> 3 * * * * :每小时的第三分钟执行一次 2> 3 4 * * 5 :每周的周五4:03执行一次 3> 5 6 7 * * :每月的7号6:05执行一次 4> 7 8 9 10 * :每年10月9号8点7分执行一次 (3)离散取值:在时间上使用逗号分隔的多个值:#,#,# 示例: 5> 9 8 * * 3,7 :每周三周日的8点9分执行一次 6> 0 8,20 * * 3,7 :每周三周日的8:00跟20:00执行一次 (4)连续取值:在时间点上使用-链接开头和结束:#-# 示例: 7> 0 9-18 * * 1-5 :从周一到周五的9点到18点每小时执行一次 (5)在指定时间范围上,定义步长: /#: #即为步长 注:1)指定时间点不能被步长整除时,其意义将不复存在: 2)最小时间单位为“分钟”,想完成“秒”级任务,需要借助于其他机制:定义成每分钟任务,而在利用脚本实现的每分钟之内循环多次 用户cron crontab命令定义,每个用户都有专用的cron任务文件:/var/spool/cron/USERNAME 只有该用户定义了cron任务才能通过该文件看到相应信息。 注:1)每行定义一个cron任务,共6个字段(不需要指定用户);2)邮件发送给当前用户 crontab命令 使用格式: crontab [-u user] [-l | -r | -e] [-i] -l: 列出所有任务; -e: 编辑任务; -r: 移除所有任务; -i:同-r一同使用,以交互式模式让用户有选择地移除指定任务; -u user: 仅root可运行,代为为指定用户管理cron任务; 注意:运行结果以邮件通知给相关用户;如果不想接收邮件则可使用如下命令实现 (1) COMMAND > /dev/null (2) COMMAND &> /dev/null 思考: (1) 如何在秒级别运行任务? * * * * * for min in 0 1 2; do echo "hi"; sleep 20; done (2) 如何实现每7分钟运行一次任务? sleep命令: sleep NUMBER[SUFFIX]... SUFFIX: s: 秒, 默认 m: 分 h: 小时 d: 天 练习: 1、每4小时备份一次/etc目录至/backup目录中,保存的文件名称格式为“etc-yyyy-mm-dd-HH.tar.xz”; 在/etc/crontab文件中添加如下: 1 2 3 4 5 6 7 04***. /test/bak_etc cat bak_etc #!/bin/bash #bakup/etcdiratory #autherchawandate:20160908 cp /etc/ * /bakup/etc $( date +%F-%H) xz /bakup/etc $( date +%F-%H) 2、每周2, 4, 7备份/var/log/messages文件至/logs目录中,文件名形如“messages-yyyymmdd”; * * * * 2,4,7 ./test/logs 1 2 3 4 5 cat /test/logs #!/bin/bash #bakup/var/log/messagesto/logs cp /var/log/messages /logs/messages $( date +%F) xz /logs/messages $( date +%F) 3、每两小时取出当前系统/proc/meminfo文件中以S或M开头的信息追加至/tmp/meminfo.txt文件中; 1 02*** cat /proc/meminfo | grep "^[SM]" >> /tmp/meminfo .txt 4、工作日时间内,对用户docker每小执行一次“ip addr show”命令; 切换至docker用户使用命令crontab -e进入编辑界面 加入"0 9-18 * * 1-5 docker ip addr show"信息后保存退出 1 2 [docker@docker~]$ crontab -l 09-18**1-5ipaddrshow 本文转自 紫色的茶碗 51CTO博客,原文链接:http://blog.51cto.com/chawan/1853509,如需转载请自行联系原作者

优秀的个人博客,低调大师

消息中间件(一)基础

消息中间件是用于分步式系统之间收发消息的组件。 消息中间件的作用 1. 应用解耦 2. 异步处理 比如用户注册场景,注册主流程完成以后,需要调用邮件系统发送邮件通知用户注册成功,可能还需要调用其他系统。这是串行的,如果一个系统依赖很多系统,那么这个主流程会比较长,耦合度高,整个系统维护成本也会越来越高。那么我们就可以使用消息中间件来进行解耦,通过发布订阅模式,完成用户注册之后,向中间件发送消息,这样就可以马上给用户返回,至于后续工作其他系统向中间件订阅这个消息并完成后续工作就好。这也就是一个解耦和异步处理过程。 中间件有下面两种模型 点对点模型 发布订阅模型 消息中间件的解耦和异步是两个最重要的需求点,除此之外还应该做一些其他事情比如: 保证一致性,产生消息和发送消息是一致的,也就是如果操作成功,那么消息一定发送成功;如果业务操作没有成功那么就不能发送消息 具备一定消息堆积能力,可以为后端挡住一些数据流保证后端不会被压垮 具备消息实时性,保证消息的低延迟 具备消息的可靠性,主要是可靠地存储和投递 消息系统里面应该有这样一个假设:消息一定会堆积。下游系统通常有很多,里面有重要的也不重要的,面对突发流量高峰,一定会有后端系统处理不过来的情况,从而造成消息堆积;当然还有一种情况是后端系统出现问题导致暂时无法消费消息从而造成消息中间件的消息堆积。所以中间件要起到蓄水池的作用。 数据一致性,这个很容易理解,因为是分布式异步的,但是又不能容忍数据出错,所以在性能和数据一致性方面就需要有所妥协,通常在互联网行业中采取最终一致性。需要注意的是最终一致性和弱一致性不同,弱一致性表示允许在异常情况下数据可能不一致,而最终一致性则是在某段时间内允许不一致但是最终会一致。 本文转自linuxjavachen 51CTO博客,原文链接:http://blog.51cto.com/littledevil/2068474,如需转载请自行联系原作者

优秀的个人博客,低调大师

【Android 基础】TextView的属性详解

android:autoLink :设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接。可选值(none/web /email/phone/map/all) android:autoText :如果设置,将自动执行输入值的拼写纠正。此处无效果,在显示输入法并输入的时候起作用。 android:bufferType : 指定getText()方式取得的文本类别。选项editable 类似于StringBuilder :可追加字符,也就是说getText后可调用append方法设置文本内容。spannable :则可在给定的字符区域使用样式,参见这里1、这里2。 android:capitalize :设置英文字母大写类型。此处无效果,需要弹出输入法才能看得到,参见EditView此属性说明。 android:cursorVisible:设定光标为显示/隐藏,默认显示。 android:digits:设置允许输入哪些字符。如“1234567890.+-*/% ()” android:drawableBottom:在text的下方输出一个drawable,如图片。如果指定一个颜色的话会把text的背景设为该颜色,并且同时和background使用时覆盖后者。 android:drawableLeft:在text的左边输出一个drawable,如图片。 android:drawablePadding:设置text与drawable(图片)的间隔,与drawableLeft、 drawableRight、drawableTop、drawableBottom一起使用,可设置为负数,单独使用没有效果。 android:drawableRight:在text的右边输出一个drawable。 android:drawableTop:在text的正上方输出一个drawable。 android:editable:设置是否可编辑。 android:editorExtras:设置文本的额外的输入数据。 android:ellipsize:设置当文字过长时,该控件该如何显示。有如下值设置:”start”—?省略号显示在开头;”end” ——省略号显示在结尾;”middle”—-省略号显示在中间;”marquee” ——以跑马灯的方式显示(动画横向移动) android:freezesText:设置保存文本的内容以及光标的位置。 android:gravity:设置文本位置,如设置成“center”,文本将居中显示。 android:hintText:为空时显示的文字提示信息,可通过textColorHint设置提示信息的颜色。此属性在 EditView中使用,但是这里也可以用。 android:imeOptions:附加功能,设置右下角IME动作与编辑框相关的动作,如actionDone右下角将显示一个“完成”,而不设置默认是一个回车符号。这个在EditView中再详细说明,此处无用。 android:imeActionId:设置IME动作ID。 android:imeActionLabel:设置IME动作标签。 android:includeFontPadding:设置文本是否包含顶部和底部额外空白,默认为true。 android:inputMethod:为文本指定输入法,需要完全限定名(完整的包名)。例如:com.google.android.inputmethod.pinyin,但是这里报错找不到。 android:inputType:设置文本的类型,用于帮助输入法显示合适的键盘类型。在EditView中再详细说明,这里无效果。 android:linksClickable:设置链接是否点击连接,即使设置了autoLink。 android:marqueeRepeatLimit:在ellipsize指定marquee的情况下,设置重复滚动的次数,当设置为 marquee_forever时表示无限次。 android:ems:设置TextView的宽度为N个字符的宽度。这里测试为一个汉字字符宽度 android:maxEms:设置TextView的宽度为最长为N个字符的宽度。与ems同时使用时覆盖ems选项。 android:minEms:设置TextView的宽度为最短为N个字符的宽度。与ems同时使用时覆盖ems选项。 android:maxLength:限制显示的文本长度,超出部分不显示。 android:lines:设置文本的行数,设置两行就显示两行,即使第二行没有数据。 android:maxLines:设置文本的最大显示行数,与width或者layout_width结合使用,超出部分自动换行,超出行数将不显示。 android:minLines:设置文本的最小行数,与lines类似。 android:lineSpacingExtra:设置行间距。 android:lineSpacingMultiplier:设置行间距的倍数。如”1.2” android:numeric:如果被设置,该TextView有一个数字输入法。此处无用,设置后唯一效果是TextView有点击效果,此属性在EdtiView将详细说明。 android:password:以小点”.”显示文本 android:phoneNumber:设置为电话号码的输入方式。 android:privateImeOptions:设置输入法选项,此处无用,在EditText将进一步讨论。 android:scrollHorizontally:设置文本超出TextView的宽度的情况下,是否出现横拉条。 android:selectAllOnFocus:如果文本是可选择的,让他获取焦点而不是将光标移动为文本的开始位置或者末尾位置。 TextView中设置后无效果。 android:shadowColor:指定文本阴影的颜色,需要与shadowRadius一起使用。 android:shadowDx:设置阴影横向坐标开始位置。 android:shadowDy:设置阴影纵向坐标开始位置。 android:shadowRadius:设置阴影的半径。设置为0.1就变成字体的颜色了,一般设置为3.0的效果比较好。 android:singleLine:设置单行显示。如果和layout_width一起使用,当文本不能全部显示时,后面用“…”来表示。如android:text="test_ singleLine " android:singleLine="true" android:layout_width="20dp"将只显示“t…”。如果不设置singleLine或者设置为false,文本将自动换行 android:text:设置显示文本. android:textAppearance:设置文字外观。如 “?android:attr/textAppearanceLargeInverse”这里引用的是系统自带的一个外观,?表示系统是否有这种外观,否则使用默认的外观。可设置的值如下:textAppearanceButton/textAppearanceInverse/textAppearanceLarge/textAppearanceLargeInverse/textAppearanceMedium/textAppearanceMediumInverse/textAppearanceSmall/textAppearanceSmallInverse android:textColor:设置文本颜色 android:textColorHighlight:被选中文字的底色,默认为蓝色 android:textColorHint:设置提示信息文字的颜色,默认为灰色。与hint一起使用。 android:textColorLink:文字链接的颜色. android:textScaleX:设置文字之间间隔,默认为1.0f。 android:textSize:设置文字大小,推荐度量单位”sp”,如”15sp” android:textStyle:设置字形[bold(粗体) 0, italic(斜体) 1, bolditalic(又粗又斜) 2] 可以设置一个或多个,用“|”隔开 android:typeface:设置文本字体,必须是以下常量值之一:normal 0, sans 1, serif 2, monospace(等宽字体) 3] android:height:设置文本区域的高度,支持度量单位:px(像素)/dp/sp/in/mm(毫米) android:maxHeight:设置文本区域的最大高度 android:minHeight:设置文本区域的最小高度 android:width:设置文本区域的宽度,支持度量单位:px(像素)/dp/sp/in/mm(毫米),与layout_width 的区别看这里。 android:maxWidth:设置文本区域的最大宽度 android:minWidth:设置文本区域的最小宽度 附件:Android中的长度单位详解 Android中的长度单位详解(dp、sp、px、in、pt、mm)有很多人不太理解dp、sp 和px 的区别:现在这里介绍一下dp 和sp。dp 也就是dip。这个和sp 基本类似。如果设置表示长度、高度等属性时可以使用dp 或sp。但如果设置字体,需要使用sp。dp 是与密度无关,sp 除了与密度无关外,还与scale 无关。如果屏幕密度为160,这时dp 和sp 和px 是一样的。1dp=1sp=1px,但如果使用px 作单位,如果屏幕大小不变(假设还是3.2 寸),而屏幕密度变成了320。那么原来TextView 的宽度设成160px,在密度为320 的3.2 寸屏幕里看要比在密度为160 的3.2 寸屏幕上看短了一半。但如果设置成160dp 或160sp 的话。系统会自动将width 属性值设置成320px 的。也就是160 * 320 / 160。其中320 / 160 可称为密度比例因子。也就是说,如果使用dp 和sp,系统会根据屏幕密度的变化自动进行转换。 其他单位的含义 px:表示屏幕实际的象素。例如,320*480 的屏幕在横向有320个象素,在纵向有480 个象素。 in:表示英寸,是屏幕的物理尺寸。每英寸等于2.54 厘米。例如,形容手机屏幕大小,经常说,3.2(英)寸、3.5(英)寸、4(英)寸就是指这个单位。这些尺寸是屏幕的对角线长度。如果手机的屏幕是3.2 英寸,表示手机的屏幕(可视区域)对角线长度是3.2*2.54 = 8.128 厘米。读者可以去量一量自己的手机屏幕,看和实际的尺寸是否一致。 mm:表示毫米,是屏幕的物理尺寸。 pt:表示一个点,是屏幕的物理尺寸。大小为1 英寸的1/72。 本文转自叶超Luka博客园博客,原文链接:http://www.cnblogs.com/yc-755909659/archive/2012/08/18/2645415.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android Animation(动画)---基础二(LayoutAnimationController)

LayoutAnimationController动画效果,一次出现 一、布局文件使用 动画list_item_layout.xml <?xml version="1.0" encoding="utf-8"?> <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:animation="@anim/list_item_alpha" android:animationOrder="normal" android:delay="0.8" /> 每个列表项动画list_item_alpha.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000" /> </set> 主界面布局文件activity_main.xml 特别注意要在ListView中添加android:layoutAnimation="@anim/list_item_layout" <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.mazaiting.layoutanimationcontroller.MainActivity" > <ListView android:id="@+id/listView" android:layoutAnimation="@anim/list_item_layout" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:text="测试" android:onClick="test" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:text="清空" android:onClick="clear" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> 列表布局文件item_list.xml <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/app_name" android:textSize="20sp" /> 主界面代码 public class MainActivity extends AppCompatActivity { private ListView mListView; private static final String[] STRINGS = { "BruceZhang", "Alpha", "Translate", "Blanklin", "Rotate", "GreenFrank" }; private ArrayAdapter<String> mAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mListView = (ListView) this.findViewById(R.id.listView); mAdapter = new ArrayAdapter<>(this, R.layout.item_list, STRINGS); } public void test(View view) { mListView.setAdapter(mAdapter); } public void clear(View view) { mListView.setAdapter(null); } } 二、代码配置 动画文件 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000" /> </set> 主界面布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.mazaiting.layoutanimationcontroller.MainActivity" > <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:text="测试" android:onClick="test" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:text="清空" android:onClick="clear" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> 主界面动画设置 public class MainActivity extends AppCompatActivity { private ListView mListView; private static final String[] STRINGS = { "BruceZhang", "Alpha", "Translate", "Blanklin", "Rotate", "GreenFrank" }; private ArrayAdapter<String> mAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mListView = (ListView) this.findViewById(R.id.listView); mAdapter = new ArrayAdapter<>(this, R.layout.item_list, STRINGS); // 1. 创建一个Animation对象 Animation animation = AnimationUtils.loadAnimation(this, R.anim.list_item_alpha); // 2. 使用如下代码创建LayoutAnimationController对象 LayoutAnimationController lac = new LayoutAnimationController(animation); // 3. 设置控件显示的顺序 lac.setOrder(LayoutAnimationController.ORDER_RANDOM); // 4. 为ListView设置LayoutAnimationController尚需经 mListView.setLayoutAnimation(lac); } public void test(View view) { mListView.setAdapter(mAdapter); } public void clear(View view) { mListView.setAdapter(null); } }

优秀的个人博客,低调大师

SQLite学习快速入门-- 基础介绍

一、介绍:SQLite是目前最流行的开源嵌入式数据库,主要特征有: 1). 管理简单。 2). 移植性好,SQLite生成的数据库文件可以在各个平台无缝移植。 3). 可以非常方便的以多种形式嵌入到其他应用程序中,如静态库、动态库等。 4). 易于维护。 二、用途 本地轻量级数据库的最佳选择之一,android系统的标配数据库就是这个,还有配置文件也是一方面,它更多的用于中间数据、实时数据以及小数据量个人信息的存储。 三、工具的使用 SQLite Database Browser 如下图 四、与其它数据库的区别 于access的区别,sqlite的便携性和平台无关性要远远好于access,只是在可视化操作方面确实不如access。 本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/archive/2012/02/20/2358955.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Zigbee联盟基础知识普及

做智能家居,还要了解ZigBee联盟,不是做好产品就好吗,与ZigBee联盟有什么关系?在具体说明这个问题之前,我们不妨先来了解一下ZigBee。 ZigBee实际是一种短距离、低功耗的无线通信技术,名称来源于 ZigZag——一种蜜蜂的肢体语言。当蜜蜂新发现一片花丛后会用特殊舞蹈来告知同伴发现的食物种类及位置等信息,是蜜蜂群体间一种简单、高效的传递信息方式,因此ZigBee 也被成为“紫蜂协议”。 这样解释可能还是难以让人明白。简单说,ZigBee是一种类似于WiFi和蓝牙的通信协议,能够让设备与设备之间实现无线通信。而不同的是,虽然都是无线通信技术,ZigBee在智能家居领域却有着独特优势,如功耗低(发射功率仅为1mW)、连接设备多(理论上可达六万多个)、安全性高(AES-128加密算法)等等。 考虑到智能家居系统实质上为电子产品,涉及的设备又比较多,且与用户家庭安全息息相关,ZigBee技术在智能家居行业得到广泛关注也就不足为奇了。事实上,ZigBee目前已成为智能家居领域的一种主流无线技术,被广泛应用于各类家庭智能化产品。 ZigBee是一种实现智能硬件设备连接和数据交换的无线技术,那么ZigBee联盟又是干什么的呢?接下来,就进入正题,说一说ZigBee联盟。 ZigBee联盟(ZigBee Alliance)是为消费、商业和工业应用领域创建开放式全球物联网标准的非营利性组织,在全球拥有成员公司400多家,覆盖芯片供应商,设备制造商,电视、电信运营商,认证机构,大型零售集团等产业链的各个环节。联盟董事会成员包括恩智浦半导体、康卡斯特有线、飞思卡尔半导体、艾创、克罗格、兰吉尔、罗格朗、飞利浦、施耐德、芯科、德州仪器、物联传感(亚洲区唯一董事会成员)、SmartThings(三星子公司)等13家全球知名企业。 说得简单些,ZigBee联盟是制定、优化和完善ZigBee技术标准的非营利组织,组织成员主要为世界各地的知名公司,当然,其中也有不少是来自中国。显而易见,Zigbee联盟在ZigBee技术的逐步完善过程中扮演重要角色,在智能家居乃至整个物联网领域具有重大影响。而混智能家居圈,需要了解ZigBee联盟,也就不难理解了。 那么都是哪些公司有资格成为ZigBee联盟成员呢?是不是只要加入了ZigBee联盟就能参与标准制定和完善了呢? ZigBee联盟没有对申请加入的企业作严格的限定,没有设立过高的门槛。正如上面所说,ZigBee联盟成员覆盖了多个环节,并非局限于某一方面。不过,申请加入的企业还是需要有一定的实力的,绝非随随便便就能加入。需要指出的是,加入ZigBee联盟后,成员的地位有一定的差别。 近日,WiFi联盟(WiFi Alliance)宣布推出全新的会员资格类别(实施级会员),以支持更多企业推出WiFi CERTIFIED认证产品。事实上,ZigBee联盟一直都在实行三级会员资格体系,不同级别会员所拥有的权力范围不相同。 ZigBee联盟成员分为三个级别,分别是促进者(Promoters),参与者(Participants)和采纳者(Adopters)。促进者是联盟中最有影响力的级别,可获得董事会席位;参与者则可以参与细则的制订、技术委员会候选人资格和参加研发工作;而采纳者只能得到最终通过的文书并使用完成的ZigBee规范。 比如,在今年9月23—25日举办的2015上海国际智能建筑展上,一些ZigBee联盟采纳者成员称“一直在积极的参与标准化制定和实施”是不准确的,因为“标准化制定”是“参与者”以上等级会员才能够参与的,采纳者并无权参与。再如,ZigBee联盟前不久宣布,家装零售商Lowe’s(劳氏)以“参与者”身份加入ZigBee联盟,Lowe’s就可以参与细则的制订、有资格成为技术指导委员会的候选人以及参加研发工作。 当然,无论是什么等级的会员,成为ZigBee联盟成员对企业在智能家居领域发展都是有益的。而对于智能家居企业来说,至少有机会获得并且能够影响新兴的ZigBee规范,增强产品和产业的竞争力。 作者:何妍 来源:51CTO

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码