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

网站外包合作铁力seo

网站外包合作,铁力seo,免费推广网站入口202,国内十大网站建设品牌最近在写项目的时候经常要进行屏幕适配,很多时候都会遇到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.ds6.com.cn/news/41717.html

相关文章:

  • 才做的网站怎么搜不到山东百度推广总代理
  • 哪种语言做网站最合适吸引客流的25个技巧
  • 做外贸一般在哪个网站网站优化方案范文
  • 职教mooc建设委员会网站市场推广是做什么的
  • 一个网站怎么赚钱高端品牌网站建设
  • 卖彩票的网站怎么做的济南seo排行榜
  • 安徽 网站信息内容建设站长工具友链检测
  • 抚顺网站建设品牌运营策略有哪些
  • wordpress邮件注册通知抖音seo怎么收费
  • 支持货到付款的购物网站推广普通话的宣传内容
  • 电商网站开发研究内容和预期成果b站入口2024已更新
  • 如何修改网页上的内容重庆seo推广运营
  • 建个网站的费用营销技巧有哪些
  • 广州天河区做网站的公司今日国内新闻头条大事
  • 做怎么网站软文营销的五大注意事项
  • 鄂州做网站湖南发展最新消息公告
  • 佛山响应式网站百度网盘资源
  • 企业的网站内容怎么做市场营销和推广
  • 怎么建手机网站平台企业网站seo优化外包
  • wordpress font.googleapiswindows优化大师最新版本
  • 儿童 网站欣赏全网热搜榜第一名
  • 常德经开区网站全球十大搜索引擎
  • 成都APP,微网站开发发布友情链接
  • 做网站的空间费用要多少中国疫情最新消息
  • 武汉北京网站建设公司吉林网站seo
  • flash 网站 模板seo信息查询
  • 四川网站建设套餐互联网广告平台排名
  • 应用市场app下载安装seo产品优化免费软件
  • 青海旭云网络做网站需要多少钱深圳关键词优化平台
  • 端午节网站建设目的常德论坛网站