转自:http://netsky1990.blog.51cto.com/2220666/997452

 
    在Android开发中常用到线性布局LinearLayout对界面进行具体的创建,其中android:layout_weight这个属性很重要,它可以按照程序员的控制,根据终端屏幕的大小,以相应的比例显示控件的大小,而不会把控件的大小写死,造成无法根据屏幕来自动调整控件本身的大小。
 
需要注意以下几点:
一、LinearLayout内的控件的layout_width设置为"wrap_content"
    例:
             android:layout_height="fill_parent"
             android:layout_weight="1"
             android:text="1"/>
       
             android:layout_height="fill_parent"
             android:layout_weight="2"
             android:text="1"/>
       
             android:layout_height="fill_parent"
             android:layout_weight="3"
             android:text="1"/>
    这个时候3个TextView是按照1:2:3的比例进行显示的,但是如果TextView内的文本长度过长,则会改变效果,控件并没有按照比例显示大小,比如:
   
             android:layout_height="fill_parent"
             android:layout_weight="1"
             android:text="1111111111111111111111111111111111111111111"/>
       
             android:layout_height="fill_parent"
             android:layout_weight="2"
             android:text="1"/>
       
             android:layout_height="fill_parent"
             android:layout_weight="3"
             android:text="1"/>
    办法是设置android:layout_width="wrap_content"为android:layout_width="0dp"。这样控件里的内容并不会影响控件的大小。
二、LinearLayout内的控件的layout_width设置为"fill_parent"
    例:fill_parent"
             android:layout_height="fill_parent"
             android:layout_weight="1"
             android:text="1"/>
        fill_parent"
             android:layout_height="fill_parent"
             android:layout_weight="2"
             android:text="1"/>
    这个时候整个宽度平分为3块,第一个TextView占了两块,也就是weight值越小的比例越大
    当有三个控件时,问题就来了:
        fill_parent"
             android:layout_height="fill_parent"
             android:layout_weight="1"
             android:text="1"/>
        fill_parent"
             android:layout_height="fill_parent"
             android:layout_weight="2"
             android:text="2"/>
        fill_parent"
             android:layout_height="fill_parent"
             android:layout_weight="3"
             android:text="3"/>
    此时第三个TextView没有显示,把上面三个TextView对应的weight分别改为2,3,4,又可以看到第三个控件。
    对于这种情况还不知道问题的原因是什么。
    (上面的图片好像加载有问题,估计是网络原因吧,等网络好的时候在补,想看效果的可以去我上面转的那个网址里看,或者自己试试)

Android 控件在布局中按比例放置[转]的更多相关文章

  1. 探究android控件及布局

    控件(widget) 1. TextView(该控件的一些需要注意的属性,下同) gravity="center"textSize="24sp"textColo ...

  2. android控件基本布局

    <?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=&qu ...

  3. Android 控件属性介绍

    1.LinearLayout(线性布局): 可以分为水平线性:android:orientation= " horizontal " 和垂直线性:android:orientati ...

  4. Android控件属性大全(转)

    http://blog.csdn.net/pku_android/article/details/7365685 LinearLayout         线性布局        子元素任意: Tab ...

  5. Android 手机卫士--自定义组合控件构件布局结构

    由于设置中心条目中的布局都很类似,所以可以考虑使用自定义组合控件来简化实现 本文地址:http://www.cnblogs.com/wuyudong/p/5909043.html,转载请注明源地址. ...

  6. Android编程 控件与布局

    控件和布局的继承结构 常用控件 1.TextView <?xml version="1.0" encoding="utf-8"?> <Line ...

  7. android控件的属性

    android控件的属性 本节描述android空间的位置,内容等相关属性及属性的含义 第一类:属性值为true或false android:layout_centerHrizontal 水平居中 ( ...

  8. Android 控件架构及View、ViewGroup的测量

    附录:示例代码地址 控件在Android开发的过程中是必不可少的,无论是我们在使用系统控件还是自定义的控件.下面我们将讲解一下Android的控件架构,以及如何实现自定义控件. 1.Android控件 ...

  9. UIAutomator定位Android控件的方法

    UIAutomator各种控件定位的方法. 1. 背景 使用SDK自带的NotePad应用,尝试去获得在NotesList那个Activity里的Menu Options上面的那个Add note菜单 ...

随机推荐

  1. HDU2546题解

    解题思路:先对价格排序(顺序或倒序都可以),然后,对前n-1(从1开始.排序方式为顺序)做容量为m(卡上余额)-5的01背包(背包体积和价值相等).假设dp[i][j]表示从前i个背包中挑选体积不超过 ...

  2. Win10 恢复后退键

    转自:http://www.cnblogs.com/liubaicai/p/4368261.html 自带的几种风格的页面,竟然是用的左上角虚拟后退键,这种倒行逆施的行为微软你真是够了! 一定要把后退 ...

  3. selenium+python+pycharm环境搭建

    1.安装python,配置path环境变量,验证python安装成功与否 2.安装Pycharm:Pycharm是Python的IDE,所以我们需要安装一下:下载安装Selenium 3.在官网(ht ...

  4. python实现cifar10数据集的可视化

    在学习tensorflow的mnist和cifar实例的时候,官方文档给出的讲解都是一张张图片,直观清晰,当我们看到程序下载下来的数据的时候,宝宝都惊呆了,都是二进制文件,这些二进制文件还不小,用文本 ...

  5. Android SQLite最简单demo实现(增删查改)

    本来不太想写这篇博客的,但是看到网上的关于android数据库操作的博文都讲得很详细,对于像我这样的新手入门了解SQLite的基本操作有一定难度,所以我参考了网上的一些博客文章,并自己亲自摸索了一遍, ...

  6. 23_java之IO操作

    01输入和输出 * A:输入和输出 * a: 参照物 * 到底是输入还是输出,都是以Java程序为参照 * b: Output * 把内存中的数据存储到持久化设备上这个动作称为输出(写)Output操 ...

  7. thinkphp5集成微信支付【公众号支付】快捷路径

    1 下载官方的测试用例PHP版 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=11_1 2 到vendor目录新建weixin文件夹 ...

  8. Android 4 学习(18):搜索

    参考<Professional Android 4 Development> 搜索 通过下面这几种方式可以给应用程序添加搜索功能: Search Bar Search View Quick ...

  9. delphi IOS 后台状态保存

    FormSaveState procedure TFrm.FormSaveState(Sender: TObject);begin end; http://stackoverflow.com/ques ...

  10. Windows下安装logstash

    1. 下载 https://www.elastic.co/downloads/logstash https://www.elastic.co/downloads/past-releases 2. 文档 ...