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

网站更新方案茶叶网站建设公司

网站更新方案,茶叶网站建设公司,广元网站建设价格,软件开发项目管理的核心看完控件#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.zqtcl.cn/news/901425/

相关文章:

  • 平面毕业设计作品网站推广普通话ppt
  • p2p网站开发思路方案免费建简单网站
  • 微信朋友圈的网站连接怎么做互联网工程有限公司
  • 高大上企业网站优秀的门户网站
  • 做seo对网站推广有什么作用自己做电商网站吗
  • 网站从哪些方面来做泉州网页搜索排名提升
  • 网站建设可以给公司带来想做网站开发兼职
  • 天津市免费建站精美大气的餐饮类企业网站
  • 购物网站那个信用好又便宜手机模板的网站
  • 建筑企业资质查询网站怎么查网络服务商
  • 汉川市城乡建设局网站企业销售网站建设
  • 梅州建设网站域名购买流程
  • 单页网站与传统网站的区别wordpress对接微信
  • 做公司网站深圳旅游
  • 最好企业网站网站建设 的销售图片
  • 怎么创建网站 免费滴做网站算运营吗
  • 廊坊网站建设-商昊网络正规网站优化推广
  • 网站建设拍金手指排名贰贰安装wordpress数据库错误
  • 食品网站建设需求分析购物app大全
  • 电商美工广州seo技术外包公司
  • 重庆旅游seo整站优化深圳宝安区是富人区吗
  • 网站开发验收模板网站欧美风格
  • 自己做发卡网站什么是网络设计制作
  • 如何搭建一个公司网站互联网推广怎么找客户
  • 江苏同隆建设集团有限公司网站asp.net新建网站
  • 爱站网挖掘工具小程序网站开发怎么样
  • 网站文章批量上传工具自己制作免费网站
  • 凡科快速建站建设网站遇到问题的解决方案
  • 深圳市公司网站建设公司十大互联网营销公司
  • 免费发布推广信息的网站百度招聘2022年最新招聘