`
lrc_1986
  • 浏览: 92930 次
  • 性别: Icon_minigender_1
  • 来自: 沈阳
社区版块
存档分类
最新评论

android:layout_weight

阅读更多
layout_weight是LinearLayouts的view布局里一个很重要的值。

所有的view的layout_weight缺省值都是为0,意味着他们只在屏幕上占据它们需要显示的空间大小。

activity根据这个View的比0大的layout_weight值来划分剩余的空间和其它Views定义的layout_weight也按比例进行空间的划分。
  

给个例子:假设我们在水平行上有一个文本标签和两个文本编辑框view. 文本标签没有定义layout_weight 值,所以它将占据最小的需要提供的空间. 如果每个文本框view的layout_weight 都被设置为1, 在父布局中的剩余的宽度将被它们平分.如果一个文本view的layout_weight值为1,另外一个是2, 那么剩余空间的三分之一将给第一个文本框,三分之二将给第二个文本框

这个布局文件也演示了如何在其他布局内部嵌套布局从而生成更复杂和漂亮的布局. 在这个例子中,一个水平的线性布局嵌套在另外一个垂直的布局中,从而允许标题标签和文本字段在水平方向上边界对齐


转载http://hi.baidu.com/fumingxia19/blog/item/9aa6077a151cb6e42f73b315.html
分享到:
评论
1 楼 just4you 2011-10-28  
我有三个TextView怎么办?
1:1:1是平分。
那1:1:2是怎么着啊?晕了。

相关推荐

    2011.10.13(4)——— android android:layout_weight

    NULL 博文链接:https://trylovecatch.iteye.com/blog/1195121

    android_QQ_例子

    用Eclipse加载项目工程 <LinearLayout xmlns:android=... android:layout_weight="0.66" android:background="@drawable/blue_bg" android:orientation="vertical" > android:layout

    Android实训购物车页面

    -<LinearLayout android:background="@drawable/aaa" android:weightSum="1" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" xmlns:android=...

    Android购物车代码

    -<LinearLayout android:background="@drawable/aaa" android:weightSum="1" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" xmlns:android=...

    Android控件大全以及各布局空间的使用方式

    android:layout_weight="1" android:layout_height="wrap_content" android:text="行1列2" /> <TextView android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content...

    Android 百分比布局

    android:layout_weight="1" android:orientation="horizontal"> android:id="@+id/tv_solid_number" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="本次上架...

    Android 重写RadioButton,模仿QQ消息气泡

    android:layout_weight="1" android:button="@null" android:drawableTop="@drawable/icon_click_wd" android:gravity="center" android:text="我的" android:textSize="10dp" /> --设置值,显示气泡 rb_...

    android水平导航条的实现

    我用的是HorizontalScrollView来实现水平条的滚动,按钮的背景宽度和图片的一致,以免被拉伸,main.xml的配置如下: <LinearLayout xmlns:android=... android:layout_weight="1" >

    Android实现图片自动轮换

    package xatu.cn.androidtest_one; import android.content.ContentResolver; import android.content.Intent;... android:layout_weight="1" /> </android.support.constraint.ConstraintLayout>

    九宫格牌翻转游戏demo

    android:layout_weight="1" android:src="@drawable/pbg" android:scaleType="centerCrop"/> android:id="@+id/m3" android:layout_margin= "2dp" android:layout_width="60dp" android:layout_height=...

    WeChatSample

    android:layout_weight="1" android:id="@+id/vp" android:layout_width="match_parent" android:layout_height="0dp"></android.support.v4.view.ViewPager> android:paddingTop="10dp" android:background...

    Android中的android:layout_weight使用详解

    layout_weight的作用是设置子空间在LinearLayout的重要度(控件的大小比重)。layout_weight的值越低,则控件越重要,下面为大家介绍下具体的使用方法

    高仿微信界面

    android:layout_weight="1"> </android.support.v4.view.ViewPager> android:layout_width="match_parent" android:layout_height="0.5dp" android:background="#737373" /> android:layout_width=...

    WebViewDownloadTest.zip

    android:layout_weight="10" android:text="http://www.imust.cn/info/1062/5273.htm" /> android:id="@+id/bt_go" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_...

    目录选择器源代码

    android:id="@+id/dir_str" android:gravity="center" android:layout_weight="1" /> --> android:id="@+id/btn_back" android:layout_width="40dip" android:layout_height="40dip" android:text="BACK" ...

    LCRapidDevelop-master

    android:layout_weight="1" android:layout_height="wrap_content" android:layout_marginLeft="15dp" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:layout_marginRight="10dp...

    wkp111_StickLayout-粘性控件,其任意一个子控件都可滑动停留,本质为NestedScrollView和LinearLayout的结合。.zip

     android:layout_weight="1"  android:layout_width="0dp"  android:layout_height="match_parent"/>    android:onClick="scrollTo3"  android:background="@android:color/holo_green_light"  android:...

    Parallax Everywhere-使ImageView和TextView产生视差效果.zip

     android:layout_weight="1">   android:layout_width="match_parent"  android:layout_height="match_parent"  android:layout_gravity="center"  android:layout_margin="10dp"  android:...

    android布局精解

    o 2.1、Tips:android:layout_weight="1" • 3、相对布局(Relative Layout) • 4、表格布局(Table Layout) • 5、列表视图(List View) o 5.1、一个小的改进 o 5.2、补充说明 • 6、网格视图(Grid View) ...

    SwipeListViewTest项目

    <Button android:id="@+id/example_row_b_action_2" android:layout_width="0dp" android:layout_height="60dp" android:layout_gravity="center" android:layout_marginLeft="10dp" android:layout_weight="1" ...

Global site tag (gtag.js) - Google Analytics