`
wujiandong
  • 浏览: 43530 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Android属性系列之layout_weight

阅读更多
对自己现在所了解的layout_weight属性进行记录,不求全面,只求正确!

layout_weight意为"权重",我的理解就是给组件设置一个显示大小的比例。
layout_weight设置一个值,会出现两种情况。
第一种:当组件的“layout_width”属性为“fill_parent”时,值越小,组件越大。
第二种:当组件的“layout_width”属性为“wrap_content”时,值越大,组件越大。

第一种情况:
<LinearLayout 
	android:layout_weight="1"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:orientation="horizontal"
	android:layout_marginLeft="10dp"
	android:layout_marginRight="10dp"
>
	<Button 
		android:id="@+id/btn_save"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:layout_weight="1"
		android:text="保存"
	/>
	
	<Button 
		android:id="@+id/btn_return"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:layout_weight="4"
		android:text="返回"
	/>
</LinearLayout>

在这里"保存"按钮的Layout_weight=1,"返回"按钮的Layout_weight=4,layout_width="fill_parent"时, 运行效果为:


第二种情况:
<LinearLayout 
	android:layout_weight="1"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:orientation="horizontal"
	android:layout_marginLeft="10dp"
	android:layout_marginRight="10dp"
>
	<Button 
		android:id="@+id/btn_save"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_weight="1"
		android:text="保存"
	/>
	
	<Button 
		android:id="@+id/btn_return"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_weight="4"
		android:text="返回"
	/>
</LinearLayout>

在这里"保存"按钮的Layout_weight=1,"返回"按钮的Layout_weight=4,layout_width="wrap_content"时,运行效果为:


以上为本人对已知情况的总结,如有不对或总结不足,望指教!
  • 大小: 2.5 KB
  • 大小: 2.8 KB
分享到:
评论

相关推荐

    2011.10.13(4)——— android android:layout_weight

    在Android开发中,`android:layout_weight`是一个非常重要的属性,尤其在布局管理器中,如LinearLayout。这个属性主要用于在有限的空间内分配组件的大小,根据权重比例来决定每个子视图占据的屏幕空间。本篇文章将...

    Android应用中通过Layout_weight属性用ListView实现表格

    在Android应用开发中,`Layout_weight`属性是一个非常关键的概念,尤其在使用`LinearLayout`时。`Layout_weight`用于在`LinearLayout`中控制子视图(Views)如何平分剩余空间,这对于创建灵活且响应式的用户界面至关...

    apktool layout_weight Base64

    2. Android布局系统中的layout_weight属性,以及如何通过设置权重来动态调整视图的大小。 3. Base64编码和解码的概念,以及在Android开发中的应用场景。 4. 如何使用Java内置的Base64工具进行编码和解码,或者如何在...

    Android中的android:layout_weight使用详解

    在Android开发中,`android:layout_weight`是一个关键属性,特别是在使用`LinearLayout`进行界面布局时。`layout_weight`用于指定一个子视图在父视图中的权重,它决定了控件如何分配额外的空间,尤其是在视图的尺寸...

    Android_layout.rar_android_android 布局_layout

    关键属性有`orientation`(设置布局方向,可选垂直或水平)、`weight`(分配子视图的额外空间比例)以及`layout_gravity`(设置子视图在父视图中的位置)。 2. **RelativeLayout**:相对布局允许子视图相对于其他...

    Android weight属性demo

    在Android开发中,`weight`属性是LinearLayout布局管理器中的一个重要概念,用于实现视图组件的权重分配,尤其是在处理屏幕尺寸适配时显得尤为重要。`weight`属性是Android为了解决在不同分辨率和屏幕尺寸设备上保持...

    Android移动开发-Weight计算.zip

    在Android移动开发中,"Weight"一词通常与布局管理器相关,特别是LinearLayout中的`layout_weight`属性。这个属性在创建动态、响应式界面时非常关键,因为它允许开发者分配视图组件之间的空间比例,而不仅仅是固定...

    Android layout_weight使用方法及实例

    在Android开发中,`layout_weight`属性是LinearLayout布局中的一个重要特性,它允许我们在有限的空间内按比例分配子视图的宽度或高度。`layout_weight`主要用于实现灵活的界面设计,尤其是在需要子视图等宽或者根据...

    Android_layout_详细介绍

    子控件可以通过设置`layout_weight`属性来控制在布局中的相对大小,实现灵活的控件宽度分配。例如,两个`TextView`控件,如果一个的`layout_weight`设为1,另一个设为2,则后者会占据更多的宽度。 - **对齐方式**:...

    weightDemo

    `layout_weight`属性是LinearLayout布局管理器的一个重要特性,用于在有限的空间内灵活分配子视图(View)的大小。本教程将深入探讨`layout_weight`属性,帮助你更好地理解和运用这一功能。 `layout_weight`属性在...

    Android期末作品,课表

    尤其在描述中提到的`android:layout_weight`属性,是Android布局设计中的一个关键概念,用于实现灵活的屏幕适配。 `android:layout_weight`是LinearLayout布局中的一个特性,主要用于在有限的空间内分配子视图...

    Layout_table android网格布局

    - **权重分配**:在TableRow中,可以使用`android:layout_weight`属性为控件分配权重,决定控件占据的列宽比例。 4. **Spanned Cells(跨列):** - 通过设置`android:layout_span`属性,可以让一个控件跨越多列...

    4种Android屏幕自适应解决方案

    Android支持多屏幕机制即用为当前设备屏幕提供一种合适的方式来共同管理并解析应用资源。本文就介绍了4中Android屏幕自适应解决方案。...传统的layout_weight使用方法是将当前控件的layout_width和layout_

    Android学习指南之Layout 布局--千锋培训

    【Android学习指南之Layout 布局】 在Android开发中,布局(Layout)是构建用户界面的核心元素,它负责组织和定位应用中的各个视图组件。本指南将着重讲解三种主要的布局类型:LinearLayout、RelativeLayout和...

    Android的Layout完全介绍

    android:layout_weight="1" android:layout_height="wrap_content" android:text="Button 1" /&gt; android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:...

    Android布局文件的属性值解析

    `android:layout_weight` 属性用于分配视图在容器中剩余空间的比例。通常与 `match_parent` 配合使用来实现灵活的布局。例如: ```xml android:layout_width="match_parent" android:layout_height="wrap_...

    Android 控件说明

    - `layout_weight`:用于确定视图在容器中的相对大小,特别是在`LinearLayout`中,当设置了`layout_weight`时,如果`layout_width`或`layout_height`设置为`match_parent`,则会根据权重分配空间。 - `layout_...

Global site tag (gtag.js) - Google Analytics