`
wujiandong
  • 浏览: 43202 次
  • 性别: 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
分享到:
评论

相关推荐

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

    主要介绍了Android应用中通过Layout_weight属性用ListView实现表格的方法,文中对Layout_weight属性先有一个较为详细的解释,需要的朋友可以参考下

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

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

    Android App中的多个LinearLayout嵌套布局实例解析

    查了下资料,说是要设置layout_weight属性 资料说得不是很清楚,也没仔细看,就去弄,结果越弄越混乱。 于是静下心来,自己写xml测试,发现如下。 如果LinearLayout是最外面的一层,它是不会弹出layout_weight属性的...

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

    android:layout_weight="1" android:layout_height="wrap_content" android:text="行1列2" /&gt; &lt;TextView android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content...

    weightDemo

    对android布局中的layout_weight属性进行深入讲解。

    Android上拉面板AndroidSlidingUpPanel.zip

    如果您想定义高度屏幕为percetange,可将其设置为match_parent,滑动视图定义为layout_weight属性。  默认情况下,整个面板将作为拖动区域和将截获的点击和拖动事件。可以通过使用setDragView方法或...

    SwipeListViewTest项目

    &lt;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" ...

    LoadingLayout-一个可以控制页面4种加载状态的控件.zip

     android:layout_weight="1"  app:emptyView="@layout/empty_view"  &gt;  你的原有的内容布局  &lt;/com.xiaomagouche.loadinglayout.library.LoadingLayout&gt;2. 控制状态变化LoadingLayout loadingLayout = ...

    CircleIndicator-一个轻量级的viewpager指示器 ,类似于nexus5 启动器的效果.zip

     android:layout_weight="1"&gt;  &lt;android.support.v4.view.ViewPager  android:id="@ id/viewpager_default"  android:layout_width="match_parent"  android:layout_height="match_parent"/&gt;    ...

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

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

    Android中Textview和图片同行显示(文字超出用省略号,图片自动靠右边)

    但是当我们要是图标跟着文字后面,第一时间想到用LinearLayout的layout_weight 来做,但是做出来效果不一样。 后来竟然忘记这个属性了:指定TextView的最大宽度实现自动省略 android:maxWidth=90dp ,加上

    Android给布局、控件加阴影效果的示例代码

    增加阴影效果,让控件或者布局看起来有立体的效果,总的来说有两种解决方案。 1,直接使用属性: android:elevation=”4dp”这样一句代码,就实现了... android:layout_weight=1 android:gravity=center android:e

    Android开发EditText属性.txt

    android:layout_weight="1"//权重,控制控件之间的地位,在控制控件显示的大小时蛮有用的。 android:textAppearance="?android:attr/textAppearanceLargeInverse"//文字外观 android:layout_gravity="center_vertical...

    android-CustomChoiceList-master

    Android 自定义选择列表示例 此示例演示了如何创建自定义可检查布局,以与 ListView 的 choiceMode 属性一起使用。 介绍 此示例演示了如何在 Android ... android : layout_weight = " 1 " android : paddingLeft =

    Android注册登录界布局设计

    1、selector的使用 2、style的使用 3、将一个TextView放在一个EditText中(使用相对布局…… ...6、是两个控件在同一行平均分布(这两个控件放在一个LinearLayout中,分别设置2控件的属性android:layout_weight="1

    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...

    Android布局之LinearLayout线性布局

    android:layout_weight—– 给控件分配剩余空间 先给大家展示一下导图: 知识点详解(演示效果方便组件没有设置id) (1)gravity和Layout_gravity android:gravity 属性是对该view中内容的限定.比如一个...

Global site tag (gtag.js) - Google Analytics