网站改版 理论,淘宝卖家 打电话 做网站,企业网站酷站,360优化大师官方官网RelativeLayout中子控件常用属性#xff1a;
子控件默认是从父控件的左上角开始排列的
相对于父控件 android:layout_alignParentToptrue 和父控件的顶部对齐android:layout_alignParentBottomtrue 和父控件的底部对齐android:layout_alignPar…RelativeLayout中子控件常用属性
子控件默认是从父控件的左上角开始排列的
相对于父控件 android:layout_alignParentToptrue 和父控件的顶部对齐android:layout_alignParentBottomtrue 和父控件的底部对齐android:layout_alignParentRighttrue 和父控件的右端对齐android:layout_alignParentLefttrue 和父控件的左端对齐相对于给定的ID控件
android:layout_aboveid/cat1 控件的底部置于给定ID的控件之上
android:layout_belowid/cat1 控件底部置于给定ID的控件之下·
android:layout_toRightOfid/cat1 控件的左边缘与给定ID的控件的右边缘对齐
android:layout_toLeftOfid/cat1 控件的右边缘与给定ID的控件的左边缘对齐
android:layout_alignBottomid/cat1 与给定控件的底边缘对齐
android:layout_alignLeftid/cat1 与给定控件的左边缘对齐
android:layout_alignTopid/cat1 与给定控件的定边缘对齐
android:layout_alignRightid/cat1 与给定控件的右边缘对齐
android:layout_alignBaselineid/cat1控件的Baseline与给定ID控件的Baseline对齐其实这个baseline相当于笔记本里写文字时候的底下的那条线android:layout_alignRight 本元素的右边缘和某元素的的右边缘对齐
android:layout_toRightOf 在某元素的右边居中 android:layout_centerHorizontaltrue 水平居中android:layout_centerVerticaltrue 垂直居中android:layout_centerInParenttrue 相对于父控件处在正中央一个简单的登录界面
RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:paddingBottomdimen/activity_vertical_marginandroid:paddingLeftdimen/activity_horizontal_marginandroid:paddingRightdimen/activity_horizontal_marginandroid:paddingTopdimen/activity_vertical_margintools:context.MainActivity RelativeLayoutandroid:layout_height150dpandroid:layout_width400dpandroid:layout_centerInParenttrueandroid:background#ff0000TextViewandroid:idid/userandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginTop10dpandroid:text用户:android:textSize20dpandroid:textColor#ffffff/EditTextandroid:idid/userlineandroid:layout_marginTop5dpandroid:layout_width300dpandroid:layout_height40dpandroid:layout_toRightOfid/user/TextViewandroid:idid/passwdandroid:layout_marginTop10dpandroid:layout_belowid/userandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text密码:android:textSize20dpandroid:textColor#ffffff/EditTextandroid:idid/passwdlineandroid:layout_width300dpandroid:layout_height40dpandroid:layout_belowid/userlineandroid:layout_toRightOfid/passwd/Buttonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text确定android:layout_alignParentRighttrueandroid:layout_belowid/passwdline//RelativeLayout
/RelativeLayout
所的结果 布局间的所属关系
Margin和Padding
盒模型控件主要定义四个区域内容 (content)、边框距(padding)即内边距、边界(border)和外边距(margin)。 对于初学者经常会搞不清楚marginbackground-colorbackground- imagepaddingcontentborder之间的层次、关系和相互影响。这里提供一张盒模型的平面示意图希望便于你的理解和记忆。Margin 是整体移动带着控件里面的内容content而padding 是移动控件里面的内容相对于控件Bprder的距离。 将上述界面进行美化
RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:paddingBottomdimen/activity_vertical_marginandroid:paddingLeftdimen/activity_horizontal_marginandroid:paddingRightdimen/activity_horizontal_marginandroid:paddingTopdimen/activity_vertical_margintools:context.MainActivity RelativeLayoutandroid:idid/laout1android:layout_height150dpandroid:layout_width400dpandroid:layout_centerInParenttrueandroid:background#ff0000TextViewandroid:idid/userandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginTop20dpandroid:layout_marginLeft10dpandroid:layout_marginRight10dpandroid:text用户:android:textSize20dpandroid:textColor#ffffff/EditTextandroid:idid/userlineandroid:layout_marginTop5dpandroid:layout_width300dpandroid:layout_height40dpandroid:layout_toRightOfid/user/TextViewandroid:idid/passwdandroid:layout_marginTop20dpandroid:layout_belowid/userandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginLeft10dpandroid:layout_marginRight10dpandroid:text密码:android:textSize20dpandroid:textColor#ffffff/EditTextandroid:idid/passwdlineandroid:layout_width300dpandroid:layout_height40dpandroid:layout_belowid/userlineandroid:layout_toRightOfid/passwd/Buttonandroid:idid/btn1android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_alignParentLefttrueandroid:layout_marginLeft90dpandroid:text确定android:layout_belowid/passwdline/Buttonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text取消android:layout_toRightOfid/btn1android:layout_belowid/passwdlineandroid:layout_marginLeft80dp//RelativeLayoutRelativeLayoutandroid:idid/layout2android:background#ff0000android:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:layout_belowid/laout1android:layout_marginTop10dpImageViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_margin100dpandroid:srcdrawable/picture2//RelativeLayout
/RelativeLayout如下图所示
安卓按键快速美化
在res/drawable目录下新建按钮样式文件 btn_normal.xml正常状态 和 btn_pressed.xml(按下状态)。
btn_normal.xml文件
?xml version1.0 encodingutf-8?
shapexmlns:androidhttp://schemas.android.com/apk/res/androidandroid:shaperectangle!-- 圆角的半径 --corners android:radius10dp/!-- 填充颜色 --solid android:color#3a8fea/
/shapebtn_pressed.xml文件
?xml version1.0 encodingutf-8?
shape xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:shaperectangle!-- 圆角的半径 --corners android:radius10dp/!-- 填充颜色 --solid android:color#0662f5/
/shape在res/drawable目录下新建样式文件 btn_selector.xml 文件定义按钮的不同状态样式。
btn_selector.xml文件
?xml version1.0 encodingutf-8?
selector xmlns:androidhttp://schemas.android.com/apk/res/android!-- 正常状态 --item android:drawabledrawable/btn_normal android:state_pressedfalse/!-- 按下状态 --item android:drawabledrawable/btn_pressed android:state_pressedtrue//selector练习制作刷卡界面
RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:backgrounddrawable/bg_shopping_menutools:context.MainActivity ImageView android:layout_heightwrap_contentandroid:layout_widthwrap_contentandroid:layout_centerInParenttrueandroid:srcdrawable/pic_rf/ImageViewandroid:layout_heightwrap_contentandroid:layout_widthwrap_contentandroid:layout_centerInParenttrueandroid:srcdrawable/cardandroid:paddingLeft100dpandroid:paddingTop50dp/Buttonandroid:layout_heightwrap_contentandroid:layout_widthwrap_contentandroid:layout_centerHorizontaltrueandroid:layout_marginBottom30dpandroid:layout_alignParentBottomtrueandroid:text刷卡android:backgrounddrawable/btn_selectorandroid:textColor#ff0000/RelativeLayoutandroid:layout_heightwrap_contentandroid:layout_widthmatch_parentandroid:background#00ff00TextViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textSize30dpandroid:text刷卡界面android:layout_marginLeft20dp/Buttonandroid:idid/butn1android:layout_heightwrap_contentandroid:layout_widthwrap_contentandroid:text注册android:layout_alignParentRighttrue /Buttonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text查询信息android:layout_toLeftOfid/butn1android:layout_marginRight20dp//RelativeLayout/RelativeLayout
结果如下 LinearLayout常用属性它的父控件还是RelativeLayout所以RelativeLayout的属性还可以拿来用
orientation: 布局中控件的排列方式有vertical竖直默认和horizontal水平两种方式gravity控制组件所包含的子元素的对齐方式可多个组合如left|buttom这个是基础控件相对于父控件来说的layout_gravity 控制该组件在父容器中的对齐方式这个是布局控件相对于父控件来说的layout_width布局宽度通常不直接写数字的用wrap_content(组件实际大小)和fill_parent或者match_marent(填满父容器)layout_height布局的高度参数同上background为组件设置一个背景图片或者直接用颜色覆盖
Weight权重
该属性用来等比例地划分区域。
最简单的用法要等比例划分分谁谁为0Weight按比例即可当我们设置宽度为0dp时同时设置weight属性为1意思就是在宽度方向上所占比重为1。如果将height设置为0同时设置weight属性为2意思就是在竖直方向所占比重为2。
divider分割线
该属性用于LinearLayout设置分割图片通过showDivider来设置分割线的所在位置有四个可选值none、middle、begining、end当然还可以通过
divider 为LinearLayout设置分割线的图片showDivider 设置分割线所在位置有四个通道none、middle、begining、enddividerPadding 设置分割线的Padding
设置分割线divider 然后编辑该分割线的代码
?xml version1.0 encodingutf-8?
shape xmlns:androidhttp://schemas.android.com/apk/res/android android:shapeline shape是分割线的形状sizeandroid:width200dp 分割线的宽android:height2dp 分割线的高/strokeandroid:color#000000 这个是分割线的颜色/
/shape使用线性布局和相对布局写一个丑陋的登录界面
RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:backgrounddrawable/bg_shopping_menutools:context.MainActivity LinearLayoutandroid:layout_width300dpandroid:layout_heightwrap_contentandroid:layout_centerInParenttrueandroid:orientationhorizontal LinearLayoutandroid:layout_width0dpandroid:layout_heightmatch_parentandroid:layout_weight1android:dividerdrawable/dividerandroid:showDividersmiddle|endandroid:dividerPadding2dpandroid:orientationvertical TextViewandroid:layout_widthmatch_parentandroid:layout_height0dpandroid:layout_weight1android:gravitycenterandroid:textStyleboldandroid:textSize15dpandroid:text账号 /TextViewandroid:layout_widthmatch_parentandroid:layout_height0dpandroid:layout_weight1android:gravitycenterandroid:textStyleboldandroid:textSize15dpandroid:text密码 /TextViewandroid:layout_widthmatch_parentandroid:layout_height0dpandroid:layout_weight1android:gravitycenterandroid:textStyleboldandroid:textSize15dpandroid:textID //LinearLayoutLinearLayoutandroid:layout_width0dpandroid:layout_heightmatch_parentandroid:layout_weight5android:orientationvertical EditTextandroid:layout_widthmatch_parentandroid:layout_height0dpandroid:layout_weight1 /EditTextandroid:layout_widthmatch_parentandroid:layout_height0dpandroid:layout_weight1 /EditTextandroid:layout_widthmatch_parentandroid:layout_height0dpandroid:layout_weight1 //LinearLayout/LinearLayout/RelativeLayout结果如下图所示