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

网站外包合作g3云推广

网站外包合作,g3云推广,德宏企业网站建设公司6,开封交友网站开发公司最近在写项目的时候经常要进行屏幕适配,很多时候都会遇到layout_weight属性,很多人也不太清楚这个属性是怎么去使用,包括之前我自己都有点用不好,经常会弄混淆,那么今天就来稍微整理下。 layout_weight属性的作用&…

最近在写项目的时候经常要进行屏幕适配,很多时候都会遇到layout_weight属性,很多人也不太清楚这个属性是怎么去使用,包括之前我自己都有点用不好,经常会弄混淆,那么今天就来稍微整理下。

      layout_weight属性的作用:主要是用来分配剩余空间的一个属性,可以设置它的权重。特别注意一点就是,这个属性在Linearlayout下设置才有效。

     下面我们来看看以下几种情况:

第一种情况:我们将LinearLayout的布局设置为垂直排列,并且Button的高度都设置为wrap_content,权重分别为1,2,3。然后我们看看下面的效果图

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="button1" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="2"android:text="button2" ></Button><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="3"android:text="button3" ></Button></LinearLayout>
     

从上图可以看出,是将整个屏幕的高度分成了6份,然后根据权重的大小来分配剩余的空间。button1是占1/6,button2是占1/3,button3是占1/2。

第二种情况:依然设置为LinearLayout的布局设置为垂直排列,但是我将Button的高度都设置为match_parent,各个Button所占的权重依然是1,2,3;接着看下面的效果图:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><Buttonandroid:layout_width="wrap_content"android:layout_height="match_parent"android:layout_weight="1"android:text="button1" /><Buttonandroid:layout_width="wrap_content"android:layout_height="match_parent"android:layout_weight="2"android:text="button2" ></Button><Buttonandroid:layout_width="wrap_content"android:layout_height="match_parent"android:layout_weight="3"android:text="button3" ></Button></LinearLayout>

咦,大家一看肯定很迷糊,这个Button3跑哪去了呢?当设置了layout_weight这个属性之后,那么这个View的高度就等于原来的高度加上剩余空间所占的比例。那么剩余空间怎么求呢?下面我来告诉大家,对于这里来说,求的就是剩余的高度:首先我们假设屏幕的高度是height,因为每个View都是设置的match_parent,所以每个View的高度都是height,那么这里有三个Button,也就是三个View,剩余的高度就是用屏幕的高度-3*view的高度,height-3*height=-2height,这样我们就把剩余的高度求出来了,下面我们分别算出每个Button的高度:button1 = height+(-2*height)*1/6 = 2/3height;button2的高度为:button2 = height + (-2*height)*1/3 = 1/3height;button3的高度为:button3 = height  + (-2*height)*1/2 = 0;所以根据计算的结果,屏幕的高度分配就是2:1:0,所以button3就没有空间可以显示了。


第三种情况:我们将LinearLayout的布局设置为水平排列,并且Button的宽度都设置为wrap_content,权重分别为1,2。然后我们看看下面的效果图:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal" ><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="button1" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="2"android:text="button2" ></Button></LinearLayout>

从上图可以看出,是将整个屏幕的高度分成了3份,然后根据权重的大小来分配剩余的空间。button1是占1/3,button2是占2/3。

第四种情况:依然设置为LinearLayout的布局设置为水平排列,但是我将Button的宽度都设置为match_parent,各个Button所占的权重依然是1,2,3;接着看下面的效果图:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal" ><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:text="button1" /><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="2"android:text="button2" ></Button><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="3"android:text="button3" ></Button></LinearLayout>

button3依然没有显示出来,这里就不分析了,就是把上面的高度改为宽度,然后就自己去算吧,原理都是一样的。

最后来稍稍总结一下吧:首先 layout_weight这个属性是在LinearLayout中设置才有效,当LinearLayout的方向为垂直排列的时候,我们layout_weight是针对高度来进行权重的分配;LinearLayout的方向为水平排列的时候,我们layout_weight是针对宽度来进行权重的分配。


http://www.zhongyajixie.com/news/45101.html

相关文章:

  • 营销型网站建设市场分析有哪些搜索引擎
  • app开发与网站开发优化大师win10能用吗
  • 企业免费自助建站系统服务网站排名咨询
  • wordpress 固定链接设置网站优化排名软件网
  • 成都有哪些做网站的seo优化培训学校
  • 网站优化方案和实施湖南网站建设seo
  • 如何做简单的网站 域名邮箱建网站教学
  • 网站建设的市场定位的方案宁波关键词优化排名工具
  • 科技网站备案seo技术网网
  • 如何做个网站做cpa怎么做好推广
  • 帮做装修设计的网站北京seo服务行者
  • 网站设置多少个关键词市场营销分析案例
  • 网站精品案例真正免费的网站建站平台运营
  • wordpress locahost长沙网络优化产品
  • 安丘网站建设多少钱网上竞价
  • 做微信小程序的网站新东方留学机构官网
  • 安徽平台网站建设公司做推广
  • 扬中网站建设价格千锋教育培训机构就业率
  • wordpress数据库里更改域名福州短视频seo
  • 泰安市建设信息网站沈阳网站关键字优化
  • 您的网站未备案实时军事热点
  • 郑州网站推广公司电话市场调研报告ppt
  • asp动态网站开发认证模拟判断题百度seo关键词优化方案
  • 北京网站制作网络推广公司网络营销专业是干嘛的
  • 陕西企业网站建设哪家专业短视频seo询盘获客系统软件
  • 网站开发学那个语言比较好口碑营销的重要性
  • 无锡制作网站百度链接提交
  • 科学城做网站公司济宁百度推广电话
  • 商城网站开发业务推广公司
  • 做支付网站游戏推广怎么找玩家