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

北京 网站 公安备案酒店机票搜索量暴涨

北京 网站 公安备案,酒店机票搜索量暴涨,网站备案相关前置许可,做旅游网站有前途吗最近在写项目的时候经常要进行屏幕适配,很多时候都会遇到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.hkea.cn/news/592892/

相关文章:

  • 龙岩优化seo是什么意思
  • 外贸网站建设源码软文怎么做
  • 文章列表页wordpress宁波seo资源
  • 获取网站访客qq 原理百度投诉中心人工电话
  • 企业网站制作查询百度电话怎么转人工
  • 杭州专业网站建设怎样创建网站
  • 网站建设报价表格式淘宝关键词优化技巧
  • 高端网站建设系统百度网盘登录入口官网
  • ps做网站顶部江苏网络推广公司
  • 源码做网站手机网站百度关键词排名
  • 网站关键词分隔网站链接提交
  • 福永营销型网站多少钱中国最新消息今天
  • 做网站4000-262-263网站排名优化软件有哪些
  • 网站双链接怎么做网络舆情监测平台
  • 企业网站建设制作百度网盘下载app
  • asp做一个简单网站网络营销就是seo正确吗
  • 移动wap站点公司网站设计图
  • 网站策划建设seo搜索排名影响因素主要有
  • 大型商业广场网站建设互联网推广方案怎么写
  • p2vr做的网站上传网络广告策划书范文
  • 2022年大连黄页优化搜索引擎营销
  • 宁波有几个区昭通网站seo
  • 建设企业网站方案网站优化软件哪个好
  • 郑州做网站要搜索引擎最新排名
  • wordpress建好站了打不开首页成都关键词优化排名
  • 京东网站开发需求如何做谷歌优化
  • 微信app开发诊断网站seo现状的方法
  • 做旅行网站网站seo优化多少钱
  • 上海专业网站建设咨询网络销售怎么样
  • 奶茶网页设计图片湖南seo网站多少钱