【未解决】android 权重中RelativeLayout如何指定权重weight

android之线性布局LinearLayout以及weight权重使用 - CSDN博客
android之线性布局LinearLayout以及weight权重使用
LinearLayout(线性布局):
:layout/activity_main.xml
&LinearLayout xmlns:android=&/apk/res/android&
& & xmlns:tools=&/tools&
& & android:layout_width=&match_parent&
& & android:layout_height=&match_parent&
& & android:orientation=&vertical&&
& &&LinearLayout&
& & & &android:layout_width=&match_parent&
& & & &android:layout_height=&wrap_content&
& & & &android:orientation=&horizontal&&
& & & &&TextView android:layout_width=&wrap_content&
& & & & & &android:layout_height=&wrap_content&
& & & & & &android:text=&用户名:&/&
& & & &&EditText android:layout_width=&0dp&
& & & & & &android:layout_height=&wrap_content&
& & & & & &android:hint=&请输入1-10个字符&
& & & & & &android:layout_weight=&1&/&
& & & &&/LinearLayout&
& & & & &LinearLayout&
& & & &android:layout_width=&match_parent&
& & & &android:layout_height=&wrap_content&
& & & &android:orientation=&horizontal&&
& & & &&TextView android:layout_width=&wrap_content&
& & & & & &android:layout_height=&wrap_content&
& & & & & &android:text=&密 & 码:&/&
& & & &&EditText android:layout_width=&0dp&
& & & & & &android:layout_height=&wrap_content&
& & & & & &android:hint=&请输入1-10个字符&
& & & & & &android:layout_weight=&1&
& & & & & &android:password=&true&/&
& &&/LinearLayout&
&&LinearLayout&
& & & &android:layout_width=&match_parent&
& & & &android:layout_height=&wrap_content&
& & & &android:orientation=&horizontal&
& & & &android:layout_marginTop=&20dp&&
& & & &&View android:layout_width=&0dp&
& & & & & &android:layout_height=&30dp&
& & & & & &android:layout_weight=&1&
& & & & & &/&
& & & &&Button
& & & & & &android:layout_width=&wrap_content&
& & & & & &android:layout_height=&30dp&
& & & & & &android:background=&@drawable/btn_bg&
& & & & & &android:drawableLeft=&@drawable/login32x32&
& & & & & &android:text=&登陆& /&
& & & & &&View android:layout_width=&0dp&
& & & & & &android:layout_height=&30dp&
& & & & & &android:layout_weight=&1&
& & & & & &/&
& & & &&Button android:text=&退出&
& & & & & &android:drawableLeft=&@drawable/exit32x32&
& & & & & &android:background=&@drawable/btn_bg&
& & & & & &android:layout_width=&wrap_content&
& & & & & &android:layout_height=&30dp&/&
& & & &&View android:layout_width=&0dp&
& & & & & &android:layout_height=&30dp&
& & & & & &android:layout_weight=&1&
& & & & & &/&
& & & &&/LinearLayout&
&/LinearLayout&
本文已收录于以下专栏:
相关文章推荐
也许你正在使用这个属性Layout_weight权重,没错就是它,很多人问这有什么可讲的,不就是按照那样用吗?其实任何一东西的存在都有其原因。仔细研究你会有不同的感受,当然,肯定也会有很多大神知道,小...
由于Android设备的尺寸大小不一,种类繁多,当我们在开发应用的时候就要考虑屏幕的适配型了,尽可能让我们的应用适用于主流机型的尺寸,这样我们的应用不会因为尺寸不同而不美观,解决屏幕适配问题的方法有很...
平常我们在使用线性布局LinearLayout的时候,会用到权重layout_weight,将控件的宽度(或高度)设为0,再设置它的权重即可,控件呈现呈现出的大小与权重比例相吻合。方法简单,自是没有什...
首先看一下奇怪的的现象:
线性布局的情况下,有个非常奇怪的属性----android:layout_weight,该属性大部分视图控件中都有,它表示视图的重要度或者权重,看看以下两种情况下该属性...
欢迎大家怒戳点击去来看,有好东西哦==。。相对布局LinearLayout权重weight的用法
以前一直没弄懂Layout_weight是什么意思,自己写代码测试也出来了不同的情况,最近看了一篇帖子感觉分析的很好,转贴出来学习下。
布局文件是:
    android:o...
一、动态添加控件、设置参数
这个难度比较大,放在前面讲,用的也比较多,普通情况下,我们会提前把布局XML写好,然后对XML中的元素进行设置,但这种方法在有些情况下就显得不适合,比较聊天应用,比如帖子的...
是这样的,卤煮最近刚写一个性能自动化监控工具,其中针对播放器那块需要监控内存和cpu,选用的框架是instrumentation框架,所以只能用api方式啦。当然,获取内存数据其实有很多方式,包括
前言:家和万事兴
博主这段时间工作实在是太忙了,全天无尿点……博客一直没更新,实在对不住大家……
现在CSDN的图片上传功能又废了……等会再传图片吧……真是服了……
这篇就给大家讲setShade...
他的最新文章
讲师:宋宝华
讲师:何宇健
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)android:layout_weight 权重
android:layout_weight 权重
LinearLayout子控件最重要的属性&
android:layout_weight, & 值为整数,&
此文来自: 马开东云搜索
转载请注明出处 网址:
此文原标题: android:layout_weight 权重
来源网址:
&&& 1 当父控件LinearLayout中android:orientation="vertical"时
& &&& & & 子控件高度 = 子控件原本高度 &+ &(父控件LinearLayout高度 - 所有子控件高度之和) &* &子控件高度权重比
&&&&2 当父控件LinearLayout中android:orientation="horizontal",&
& & & & &&&子控件宽度 = 子控件原本宽度 &+ &(父控件LinearLayout宽度 - 所有子控件宽度之和) * &子控件宽度权重比
& & & & & (match_parent或fill_parent都指指父控件高度或宽度)
&LinearLayout&xmlns:android="
&&&&android:layout_width="match_parent"
&&&&android:layout_height="match_parent"
&&&&android:orientation="vertical"
&&&&&TextView
&&&&&&&&android:layout_width="match_parent"
&&&&&&&&android:layout_height="match_parent"
&&&&&&&&android:textColor="#f00"
&&&&&&&&android:background="#0f0"
&&&&&&&&android:text="上面"
&&&&&&&&android:textSize="40sp"&
&&&&&&&&android:layout_weight="1"
&&&&&&&&/&
&&&&&TextView
&&&&&&&&android:layout_width="match_parent"
&&&&&&&&android:layout_height="match_parent"
&&&&&&&&android:textColor="#0f0"
&&&&&&&&android:background="#00f"
&&&&&&&&android:text="中间"
& & & & android:textSize="40sp"&
&&&&&&&&android:layout_weight="1"
&&&&&&&&/&
&&&&&TextView
&&&&&&&&android:layout_width="match_parent"
&&&&&&&&android:layout_height="match_parent"
&&&&&&&&android:textColor="#0f0"
&&&&&&&&android:background="#f00"
&&&&&&&&android:text="下面"
&&&&&&&&android:textSize="40sp"&
&&&&&&&&android:layout_weight="1"
&&&&&&&&/&
&/LinearLayout&
----&子控件高度 = 子控件原本高度 &+ &(
LinearLayout高度 - 所有子控件高度之和) &* &子控件高度权重比
上面第个子控件TextView的高度&
& & = 1屏高 + [ (1屏高 - 3屏高) &* &1/(1+1+1) &]
& & = 1屏高 + [-2屏高*(1/3) ]
& & = 1屏高 - 2屏高*(1/3)
& & = 1屏高 - 2/3屏高
& & = 1/3 屏高
&?xml&version="1.0"&encoding="utf-8"?&&&
&LinearLayout&xmlns:android="
&&&&android:orientation="vertical"&&
&&&&android:layout_width="fill_parent"&&
&&&&android:layout_height="fill_parent"&&
&EditText&&
&&&&android:layout_width="fill_parent"&&
&&&&android:layout_height="wrap_content"&&
&&&&android:gravity="left"&&
&&&&android:text="one"/&&&
&EditText&&
&&&&android:layout_width="fill_parent"&&
&&&&android:layout_height="wrap_content"&&
&&&&android:gravity="center"&&
&&&&android:layout_weight="1.0"&&
&&&&android:text="two"/&&&
& &&EditText&&
&&&&android:layout_width="fill_parent"&&
&&&&android:layout_height="wrap_content"&&
&&&&android:gravity="right"&&
&&&&android:text="three"/&&&
&/LinearLayout& &
**使用公式----&子控件高度 = 子控件原本高度 &+ &(
LinearLayout高度 - 所有子控件高度之和) &* &子控件高度权重比
**(1) one的高度 = one高度 + [1屏高 - (one高度+two高度+three高度) ] * 0/(1+0+0)&
& & & & & & & & & & & & = one高度 + 0
& & & & & & & & & & & & = one高度
& (2)two的高度 & = two高度 +[1屏高 - (one高度+two高度+three高度) ] * 1/(1+0+0)&
& & & & & & & & & & & &&=&one高度 +[1屏高 - (one高度+one高度+one高度) ] &
& & & & & & & & & & & & =&one高度 +[1屏高 - 3one高度]
& & & & & & & & & & & & = 1屏高 - 2one高度
& (3)three的高度 =&one高度 + [1屏高 - (one高度+two高度+three高度) ] * 0/(1+0+0)&
& & & & & & & & & & & &&=&one高度 + 0
' & & & & & & & & & & & = one高度 =&three高度
&?xml&version="1.0"&encoding="UTF-8"?&
&LinearLayout&xmlns:android="
&&&&android:layout_width="fill_parent"
&&&&android:layout_height="wrap_content"
&&&&android:orientation="horizontal"&&
&&&&&TextView
&&&&&&&&android:background="#ff0000"
&&&&&&&&android:layout_width="**"
&&&&&&&&android:layout_height="wrap_content"
&&&&&&&&android:text="1"
&&&&&&&&android:textColor="@android:color/white"
&&&&&&&&android:layout_weight="1"/&
&&&&&TextView
&&&&&&&&android:background="#cccccc"
&&&&&&&&android:layout_width="**"
&&&&&&&&android:layout_height="wrap_content"
&&&&&&&&android:text="2"
&&&&&&&&android:textColor="@android:color/black"
&&&&&&&&android:layout_weight="2"&/&
&&&&&&TextView
&&&&&&&&android:background="#ddaacc"
&&&&&&&&android:layout_width="**"
&&&&&&&&android:layout_height="wrap_content"
&&&&&&&&android:text="3"
&&&&&&&&android:textColor="@android:color/black"
&&&&&&&&android:layout_weight="3"&/&
&/LinearLayout&
& **使用公式
子控件宽度 = 子控件原本宽度 &+ &(父控件LinearLayout宽度 - 所有子控件宽度之和) * &子控件宽度权重比&
&&** 当三个
android:layout_width="**"都改为
android:layout_width="
wrap_content"时, 三个TextView的原本宽度一样宽,该宽度下面使用X表示
& & & & 第1个TextView宽度 = X + (1屏宽 - 3X) * 1/(1+2+3)
& & & & & & & & & & & & & & & & & & & & & &= X + (1屏宽 - 3X) * 1/6
& & & & & & & & & & & & & & & & & & & & & &=X- (1/2)X + (1/6)屏宽
& & & & & & & & & & & & & & & & & & & & & & = (1/2)X + (1/6)屏宽
& & & & 第2个TextView宽度 = X+ (1屏宽 - 3X) * 2/(1+2+3)
& & & & & & & & & & & & & & & & & & & & & &= X+ (1屏宽 - 3X) * 1/3
& & & & & & & & & & & & & & & & & & & & & &= X- X+ (1/3)屏宽
& & & & & & & & & & & & & & & & & & & & & & = (1/3)屏宽
& & & & 第3个TextView宽度 = X+ (1屏宽 - 3X) * 3/(1+2+3)
& & & & & & & & & & & & & & & & & & & & & &&= X + (1屏宽 - 3X) * 1/2
& & & & & & & & & & & & & & & & & & & & & & = X- (3/2)X + (1/2)屏宽
& & & & & & & & & & & & & & & & & & & & & & = (1/2)屏宽 - (1/2)X
android:layout_width="**"
android:layout_width="
fill_parent"时, 并把原android:layout_weight改为 & android:layout_width="
fill_parent"时, 并把原android:layout_weight改为 &

参考资料

 

随机推荐