当前位置: 首页 > news >正文

临沂市网站建设_网站建设公司_代码压缩_seo优化

在线买房网站建设 方案,成都房产网上政务大厅,郑东新区建设局网站,域名拦截检测网站看完控件#xff0c;紧接着看布局#xff0c;布局是可以来放置控件#xff0c;管理控件的。布局里也可以嵌套布局。我们新建项目UILayoutTest项目#xff0c;活动名和布局名选择默认。加入活动及其对应的布局已经创建完成。线性布局(LinearLayout)android:layout_gravity属…看完控件紧接着看布局布局是可以来放置控件管理控件的。布局里也可以嵌套布局。我们新建项目UILayoutTest项目活动名和布局名选择默认。加入活动及其对应的布局已经创建完成。线性布局(LinearLayout)android:layout_gravity属性 android:layout_weight属性相对布局(RelativeLayout)相对于父布局定位 相对于控件定位注意当一个控件去引用另一个控件的id时该控件一定要定义在引用控件的后面不然会找不到id的情况LinearLayout布局会将它所包含的控件在线性方向上一次排列所谓线性方向可能是垂直方向或者是水平方向前面我们都是在垂直方向上排列控件我们可以通过android:orientation属性指定了排列方向是vertical如果指定的是horizontal控件就会在水平方向上排列了。修改activity_layout.xml新增加三个按钮我们可以想不写android:orientation属性发现3个按钮根据自身大小水平排列因为这是LinearLayout布局默认的控件排列方式倘若你的第一个控件的android:layout_widthmatch_parent就是说你的一个控件的宽度等于整个屏幕的宽度那么你后面的哪个控件很有可能显示不出来。 等到我们写过android:orientationvertical我们会发现3个按钮垂直的排列了。?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:orientationverticalandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:contextcom.example.uilayouttest.MainActivityButtonandroid:idid/button1android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textButton 1/Buttonandroid:idid/button2android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textButton 2/Buttonandroid:idid/button3android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textButton 3android:textAllCapsfalse//LinearLayout 这里需要注意如果LinearLayout的排列方式是horizontal内部的控件就不能将宽度指定为match_parent因为这样单独一个控件会将整个水平方向占满其他控件就没有可以放置的位置了。同样的道理如果LinearLayout的排列方式是horizontal内部控件就不能将高度指定为match_parent因为这样单独一个控件会将整个垂直方向占满。 我们首先来看布局的android:layout_gravity属性我们之前看过android:gravity属性这两者有些相似。区别是android:gravity是指定文字在控件中的对齐方式而android:layout_gravity是指定控件在布局中的对齐方式。两者的可选值差不多但是需要注意LinearLayout的排列方向是horizontal时只有垂直方向上的对齐方式才会生效因为此时水平方向的长度是不固定的每增加一个控件水平方向上的长度都会改变因而无法指定该方向上的对齐方式。同样道理当LinearLayout的排列方向是vertical时只有水平方向上的对齐方式才会生效。修改activity_main.xml文件代码如下 ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/tools android:orientationhorizontalandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:contextcom.example.uilayouttest.MainActivityButtonandroid:idid/button1android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_gravitytopandroid:textButton 1/Buttonandroid:idid/button2android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_gravitycenter_verticalandroid:textButton 2/Buttonandroid:idid/button3android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_gravitybottomandroid:textButton 3android:textAllCapsfalse//LinearLayout 我们再来看LineraLayout中另一个重要属性android:layout_weight。它允许我们使用比例的方式来指定控件的大小它可以去适应手机的屏幕。下面我们来编辑一个消息发现界面需要一个文本编辑框和一个发送按钮修改activity_main.xml中的代码如下所示: ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:orientationhorizontalandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:contextcom.example.uilayouttest.MainActivityEditTextandroid:idid/input_messageandroid:layout_width0dpandroid:layout_heightwrap_content android:layout_weight3android:hintType something/Buttonandroid:idid/sendandroid:layout_width0dpandroid:layout_heightwrap_content android:layout_weight2android:textSend//LinearLayout 发现EditText和Button的宽度都指定为了0dp不过你不用担心文本编辑框和按钮不存在因为我们又接着使用了android:layout_weight属性此时控件大小由android:layout_weight来决定。这里0dp是一种比较规范的写法。另外dp是Android中用于指定控件大小、间距等属性的单位。在这里我们把EditText和Button的android:layou_weight分别设置为3和2这表明EditText占整个屏幕宽度的3份Button占2份我们是将整个屏幕分为32份。 当然我们也可以只是指定部分控件的layout_weight值来实现更好的效果。修改activity_main.xml文件中的代码如下 ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:orientationhorizontalandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:contextcom.example.uilayouttest.MainActivityEditTextandroid:idid/input_messageandroid:layout_width0dpandroid:layout_heightwrap_contentandroid:layout_weight3android:hintType something/Buttonandroid:idid/sendandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textSend//LinearLayout 我们只是指定了EditText的android:layout_weight属性并将Button的宽度改为wrap_content。这表明Button的宽度仍然按照wrap_content来计算而EditText则会占满屏幕的所有剩余空间。相对布局(RelativeLayout)android:layout_alignParentLeft属性可以让控件和父布局的左上角对齐android:layout_above属性可以让一个控件位于另一个控件的上方android:layout_alignLeft表示让一个控件的左边缘和另一个控件的左边缘对齐 相比较LinearLayoutRelativeLayout更加随意一些它通过相对定位的方式让控件出现在布局的任何位置。正因为如此RelativeLayout的属性非常多不过都是有规律可循的。修改activity_main.xml中的代码如下 ?xml version1.0 encodingutf-8? RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:orientationhorizontalandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:contextcom.example.uilayouttest.MainActivityButtonandroid:idid/button1android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_alignParentLefttrueandroid:layout_alignParentToptrueandroid:textbutton 1/Buttonandroid:idid/button2android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_alignParentRighttrueandroid:layout_alignParentToptrueandroid:textbutton 2/Buttonandroid:idid/button3android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_centerInParenttrueandroid:textbutton 3/Buttonandroid:idid/button4android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_alignParentLefttrueandroid:layout_alignParentBottomtrueandroid:textbutton 4/Buttonandroid:idid/button5android:textAllCapsfalseandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_alignParentBottomtrueandroid:layout_alignParentRighttrueandroid:textbutton 5//RelativeLayout 我们让Button 1和父布局的左上角对齐Button 2和父布局的右上角对齐Button 3居中显示Button 4 和父布局的左下角对齐Button 5 和父布局的右下角对齐。程序运行如下上面这是相对于父布局定位。 下面我们相对于控件进行定位。 修改activity_main.xml中的代码如下 ?xml version1.0 encodingutf-8? RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:orientationhorizontalandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:contextcom.example.uilayouttest.MainActivityButtonandroid:idid/button1android:layout_widthwrap_contentandroid:layout_heightwrap_content android:layout_aboveid/button3android:layout_toLeftOfid/button3android:textbutton 1/Buttonandroid:idid/button2android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_aboveid/button3android:layout_toRightOfid/button3android:textbutton 2/Buttonandroid:idid/button3android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_centerInParenttrueandroid:textbutton 3/Buttonandroid:idid/button4android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_belowid/button3android:layout_toLeftOfid/button3android:textbutton 4/Buttonandroid:idid/button5android:textAllCapsfalseandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_belowid/button3android:layout_toRightOfid/button3android:textbutton 5//RelativeLayout 其中android:layout_above属性可以让一个控件位于另一个控件的上方需要为这个属性指定相对控件的id的引用。 android:layout_toLeftOf表示一个控件位于另一个控件的左侧。注意当一个控件去引用另一个控件的id时该控件一定要定义在引用控件的后面不然会找不到id的情况。重新运行程序如下图RelativeLayout中还有另外一组相对于控件进行定位的属性android:layout_alignLeft表示让一个控件的左边缘和另一个控件的左边缘对齐android:layout_alignRight、android:layout_alignTop、android:layout_alignBottom道理是一样的。
http://www.ihoyoo.com/news/59010.html

相关文章:

  • 南京做网站南京乐识最优杭州有哪些做网站的公司好
  • 私人做网站的流程学ui设计需要要哪方面基础
  • 大数据比赛网站建设tp框架做视频网站
  • 怎么才能访问自己做的网站海外医疗网站建设
  • 南昌的网站设计做公司网站哪家好 上海
  • 中国交通建设集团第四工程局网站微营销官网
  • 政务网站开发协议下载应用软件排行榜
  • 优质网站有哪些鄞州seo整站优化服务
  • 网站横幅怎么做企业查询湖南
  • 网站建设工作室源码中国加工订单网官网
  • 襄阳seo站内优化室内装饰公司网站模板
  • 做面食视频网站网站图片的暗纹是怎么做的
  • 建筑网站设计方案网站友情链接怎么添加
  • 西安信息网站建设学编程后悔死了
  • 漳州做网站建设的公司百度经验官网首页
  • jquery网站开发实例单位做核酸检测简报
  • 世界500强企业排行榜中国企业宁波网站的优化
  • 网站建设流程详解网站备案需要多少时间
  • 做外贸soho要做网站吗镇江百度推广
  • 建设银行手机网站变淘宝网站开发语言
  • 州网站建设要找嘉艺网络网页版传奇游戏怎么制作
  • 北京网站优化平台wordpress 搭建论坛
  • 网页制作网站素材变身小说 wordpress
  • wordpress 视频不播放西安seo黑
  • 网站对接如何做购物网站排名 2019
  • 购物网站如何做基于vue.js旅游网站开发
  • 天津建站管理系统价格网站备案照片怎么弄
  • 企业网站本身应该就是企业( )的一部分html静态网页制作案例
  • 做博客网站的php代码网络工程是做什么的
  • 免费下载模板的网站有哪些wordpress创建小工具栏