惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tailwind CSS Blog
V
Vulnerabilities – Threatpost
Hacker News - Newest:
Hacker News - Newest: "LLM"
V2EX - 技术
V2EX - 技术
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Fortinet All Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
A
Arctic Wolf
美团技术团队
Cloudbric
Cloudbric
大猫的无限游戏
大猫的无限游戏
WordPress大学
WordPress大学
S
Security Affairs
T
Tenable Blog
MyScale Blog
MyScale Blog
W
WeLiveSecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
博客园_首页
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
月光博客
月光博客
宝玉的分享
宝玉的分享
博客园 - Franky
PCI Perspectives
PCI Perspectives
H
Hacker News: Front Page
D
Docker
博客园 - 司徒正美
L
LINUX DO - 最新话题
GbyAI
GbyAI
A
About on SuperTechFans
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
I
InfoQ
Microsoft Azure Blog
Microsoft Azure Blog
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
T
Threatpost
Google DeepMind News
Google DeepMind News
Help Net Security
Help Net Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
人人都是产品经理
人人都是产品经理
C
Check Point Blog
MongoDB | Blog
MongoDB | Blog
Y
Y Combinator Blog
AI
AI
有赞技术团队
有赞技术团队
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
O
OpenAI News

博客园 - meil

C#下取得Exif中照片拍摄日期 DotNet中人民币符号的输出 BAT实现照片文件批量改名 Wicket中JQuery事件绑定失效的解决 软件开发中的完整测试所包括的环节UT、IT、ST、UAT Eclipse中SVN插件的安装方式 从mysql中导出单个表结构和数据 代码帝:一个月10万行代码 PHP中使用mktime获取时间戳的一个黑色幽默 Android开发调试工具ADB的使用 Android系统权限配置 Android程序开发基础之——页面传值 Android程序开发的环境配置 SQLServer2008 动态SQL实践 ASP.net中实现双表格同步缩放不变形 Javascript实现DIV滚动自动滚动到底部 SQL Server 日期格式转换示例大全 TinyMCE使用手册 LINQ中的OrderBy实现多字段升序、降序排序实现
Android程序开发基础之——页面布局
meil · 2012-05-14 · via 博客园 - meil

1、gravity

    gravity 这个英文单词是重心的意思,在这里就表示停靠位置的意思。

    android:gravity是对元素本身说的,元素本身的文本显示在什么地方靠着换个属性设置,不过不设置默认是在左侧的。
    android:layout_gravity是相对与它的父元素说的,说明元素显示在父元素的什么位置。

    比如说button: android:layout_gravity 表示按钮在界面上的位置。 android:gravity表示button上的字在button上的位置。
    可选值:top、bottom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical。

    而且这些属性是可以多选的,用“|”分开,默认这个的值是:Gravity.LEFT

2、layout_weight

    layout_weight 用于给一个线性布局中的诸多视图的重要度赋值。

    所有的视图都有一个layout_weight值,默认为零,意思是需要显示多大的视图就占据多大的屏幕空间。若赋一个高于零的值,则将父视图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight 值以及该值在当前屏幕布局的整体 layout_weight值和在其它视图屏幕布局的layout_weight值中所占的比率而定。


     举个例子:比如说我们在 水平方向上有一个文本标签和两个文本编辑元素。

    该文本标签并无指定layout_weight值,所以它将占据需要提供的最少空间。如果两个文本编辑元素每一个的layout_weight值都设置为1,则两者平分在父视图布局剩余的宽度(因为我们声明这两者的重要度相等)。如果两个文本编辑元素其中第一个的layout_weight值设置为1,而第二个的设置为2,
   则剩余空间的三分之二分给第一个,三分之一分给第二个(数值越小,重要度越高)。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg02"
    android:orientation="horizontal" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="4"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/txtSpace1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="" />
    </LinearLayout>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/txtSpace2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="" />

        <Button
            android:id="@+id/button1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/mn_01" />

        <Button
            android:id="@+id/button2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/mn_02" />

        <Button
            android:id="@+id/button3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/mn_03" />

        <Button
            android:id="@+id/button4"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/mn_04" />
    </LinearLayout>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="4"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/txtSpace3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="" />
    </LinearLayout>

</LinearLayout>