布局: 在android 中我们常用的布局方式有这么几种: 1.LinearLayout ( 线性布局) :(里面只可以有一个控件,并且不能设计这个控件的位置,控 件会放到左上角)线性布局分为水平线性和垂直线性二者的属性分别为: android:orientation= 'horizontal ' android:orientation= 'vertical' 。 2.RelativeLayout ( 相对布局) : (里面可以放多个控件,但是一行只能放一个控件)附加几 类RelativeLayout 的属性供大家参考: 第一类: 属性值为true 或false android:layout_centerHrizontal android:layout_centerVertical android:layout_centerInparent android:layout_alignParentBottom android:layout_alignParentLeft android:layout_alignParentRight android:layout_alignParentTop android:layout_alignWithParentIfMissing 第二类:属性值必须为id 的引用名“ @id/id-name ” android:layout_below android:layout_above android:layout_toLeftOf android:layout_toRightOf android:layout_alignTop android:layout_alignLeft android:layout_alignBottom android:layout_alignRight 第三类:属性值为具体的像素值,如30dip , 40px android:layout_marginBottom android:layout_marginLeft android:layout_marginRight android:layout_marginTop 3.TableLayout ( 表格布局) : (这个要和TableRow 配合使用,很像html 里面的table)这个 表格布局不像HTML 中的表格那样灵活,只能通过TableRow 属性来控制它的行而列的话 里面有几个控件就是几列(一般情况)。如: 表示两行两列的一个表格。 android:gravity='center' 书面解释是权重比。其时就是让它居中显示。它还可以动态添加里 面的每行每列。如下代码所示: /*根据id 查找表格对象*/ TableLayout tableLayout = (TableLayout) findViewById(R.id.table01); /*创建列对象*/ TableRow tableRow = new TableRow(this); /*文本框对象*/ TextView temp = new TextView(this); temp.setText('text 的值'); /*将此文本添加到列中*/ tableRow.addView(temp); android:stretchColumns='1,2,3,4' 它的意思就是自动拉伸1,2,3,4 列。 4.AbsoluteLayout ( 绝对布局) : (里面可以放多个控件,并且可以自己定义控件的x,y 的 位置) 5.FrameLayout(帧布局):(里面可以放多个控件,不过控件的位置都是相对位置)在它里面的 控件都是按后面的一个控件叠加在前一个控件上来显示的,所有元素都被放置在最左上角。 如: android:layout_height='wrap_content' android:layout_weight='1'> android:layout_width='wrap_content' android:layout_height='wrap_content' android:visibility='invisible' android:src='@drawable/lotusleaf'> android:layout_width='wrap_content' android:layout_height='wrap_content' android:src='@drawable/frog_right' android:visibility='invisible'> 表示的是id 为f1 的控件叠加在id 为iv1 的控件上面显示 (LinearLayout 和RelativeLayout 应该又是其中用的较多的两种。AbsoluteLayout 比较少用, 因为它是按屏幕的绝对位置来布局的如果屏幕大小发生改变的话控件的位置也发生了改变。 这个就相当于HTML 中的绝对布局一样,一般不推荐使用) TextView 的属性: android:autoLink android:autoText android:bufferType android:capitalize android:cursorVisible android:digits android:drawableBottom android:drawableLeft android:drawablePadding android:drawableRight android:drawableTop android:editable android:editorExtras android:ellipsize android:freezesText android:gravity android:hintText android:imeOptions android:imeActionId android:imeActionLabel android:includeFontPadding android:inputMethod android:inputType android:linksClickable android:marqueeRepeatLimit android:ems android:maxEms android:maxLength android:lines android:maxLines android:minLines android:lineSpacingExtra android:lineSpacingMultiplier android:numeric android:password android:privateImeOptions android:scrollHorizontally android:selectAllOnFocus android:shadowColor android:shadowDx android:shadowDy android:shadowRadius android:singleLine android:text android:textAppearance android:textColor android:textColorHighlight android:textColorHint android:textColorLink android:textScaleX android:textSize android:textStyle android:typeface android:height android:maxHeight android:minHeight android:width android:maxWidth android:minWidth android:layout_centerHrizonta android:layout_centerVertical android:layout_centerInparent android:layout_alignParentBottom android:layout_alignParentLeft android:layout_alignParentRight android:layout_alignParentTop android:layout_alignWithParentIfMissing android:layout_below android:layout_above android:layout_toLeftOf android:layout_toRightOf android:layout_alignTop android:layout_alignLeft android:layout_alignBottom android:layout_alignRight android:layout_marginBottom android:layout_marginLeft android:layout_marginRight android:layout_marginTop android:gravity 在view 的靠左, 靠右等位置. 以button 为例, android:gravity='right'则button 上面的文字靠右android:layout_gravity android:layout_gravity 是用来设置该view 相对与起父view 的位置.比如一个button 在linearlayout 里,你想把该 button 放在靠左、靠右等位置就可以通过该属性设置. 以button 为例, android:layout_gravity='right'则button 靠右android:layout_alignParentRight 使当前控件的右 端和父控件的右端对齐。这里属性值只能为true 或false,默认false。android:scaleType: android:scaleType 是控制图片如何resized/moved 来匹对ImageView 的size 。 ImageView.ScaleType / android:scaleType 值的意义区别:CENTER /center 按图片的原来size 居中显示,当图片长/宽超过View 的长/宽,则截取图片的居中部分显示CENTER_CROP / centerCrop 按比例扩大图片的size 居中显示,使得图片长(宽)等于或大于View 的长(宽) CENTER_INSIDE / centerInside 将图片的内容完整居中显示,通过按比例缩小或原来的size 使得图片长/宽等于或小于View 的长/宽FIT_CENTER / fitCenter 把图片按比例扩大/缩小到 View 的宽度,居中显示FIT_END / fitEnd 把图片按比例扩大/缩小到View 的宽度,显示在 View 的下部分位置FIT_START / fitStart 把图片按比例扩大/缩小到View 的宽度,显示在 View 的上部分位置FIT_XY / fitXY 把图片 不按比例扩大/缩小到View 的大小显示 MATRIX / matrix 用矩阵来绘制,动态缩小放大图片来显示。** 要注意一点,Drawable 文 件夹里面的图片命名是不能大写的 Edittext 的属性: EditText 继承关系:View-->TextView-->EditText。EditText 的属性很 多,这里介绍几个: android:layout_gravity='center_vertical' android:hint='请输入数字! ' android:numeric='integer' android:singleLine='true' android:password='true' android:textColor = '#ff$200' android:textStyle='bold' android:textSize='20dip' android:capitalize = 'characters' android:textAlign='center' android:textColorHighlight='#cccccc' android:textColorHint='#ffff00' android:textScaleX='1.5' android:typeface='monospace' android:background='@null' android:layout_weight='1' android:textAppearance=' android:attr/textAppearanceLargeInverse' 1.EditText 默认不弹出软件键盘 方法一: 在AndroidMainfest.xml 中选择哪个activity,设置windowSoftInputMode 属性为 adjustUnspecified|stateHidden android:windowSoftInputMode='adjustUnspecified|stateHidden' 方法二: 让EditText 失去焦点,使用EditText 的clearFocus 方法 edit.clearFocus(); 方法三: 强制隐藏Android 输入法窗口 例如:EditText edit=(EditText)findViewById(R.id.edit); InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(edit.getWindowToken(),0); 2.EditText 始终不弹出软件键盘 例:EditText edit=(EditText)findViewById(R.id.edit); edit.setInputType(InputType.TYPE_NULL); Button 继承自VIEW , VIEW 有的属性它都能用 < xml version='1.0' encoding='utf-8' > android:endColor='@drawable/white' android:angle='*'/> android:color='@drawable/teal'/> android:top='*dp' android:right='**dp' android:bottom='*dp'/> android:endColor='@drawable/springgreen' android:angle='*'/> android:color='@drawable/teal'/> android:top='*dp' android:right='**dp' android:bottom='*dp'/> android:endColor='@drawable/snow' android:angle='*'/> android:color='@drawable/teal'/> android:top='*dp' android:right='**dp' android:bottom='*dp'/> Shape 样式圆滑效果: < xml version='1.0' encoding='UTF-8' > CheckBox RadioGroup Spinner TimePicker ScrollView ProgressBar RatingBar ImageView ImageButton android:background='#00000000' ImageSwicher&Gallery GradView Tab Menu |
|