`
zhiweiofli
  • 浏览: 512062 次
  • 性别: 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, 那么剩余空间的三分之二将给第一个文本框,三分之一将给第二个文本框。(数值越小表示越重要)

又例如,编辑框+按钮,这样常用的组合我们可以用以下的方式取得:
<LinearLayout android:layout_width="fill_parent"
			android:layout_height="wrap_content">

	<EditText android:layout_alignParentTop="true"
			android:layout_alignParentLeft="true" 
                        android:layout_width="wrap_content"
			android:layout_height="wrap_content" 
                        android:id="@+id/mapSearchText"
			
                        android:layout_weight="5"></EditText>

	<ImageButton android:layout_width="wrap_content"
				android:layout_height="wrap_content" 
                                android:src="@drawable/find"
				android:id="@+id/mapSearch" 

                                android:layout_weight="0"></ImageButton>
		
</LinearLayout>
 

 

分享到:
评论

相关推荐

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

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

    Android 百分比布局

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

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

    今天主要说的是对Layout_weight属性的完全解析,以及利用Layout_weight这个属性使用ListView来实现表格的效果,我们都知道Android里面专门有一个TableLayout来实现表格的,说实话,我平常开发中用TableLayout还是...

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

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

    该属性的作用是决定控件在其父布局中的显示权重,一般用于线性布局中。其值越小,则对应的layout_width或layout_height的优先级就越高,一般横向布局中,决定的是layout_width的优先级;纵向布局中,决定的是layout_...

    未加载出真正数据时的显示界面LoaderViewLibrary.zip

     android:layout_height="wrap_content" /&gt;在布局文件中定义ImageView的加载页面  android:layout_width="100dp"  android:layout_height="100dp" /&gt;用width_weight定义TextView的宽度百分比用于显示加载动画 ...

    WebViewDownloadTest.zip

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

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

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

    Android上拉面板AndroidSlidingUpPanel.zip

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

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

    Android实现图片自动轮换

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

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

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

    1,直接使用属性: android:elevation=”4dp”这样一句代码,就实现了效果,elevation表示海拔,就是布局的z轴的高度,调整高度,可以选择阴影的轻重。 &lt;TextView android:layout_width=0dp android:layout_...

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

    weightDemo

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

    高仿微信界面

    android:layout_weight="1"&gt; &lt;/android.support.v4.view.ViewPager&gt; android:layout_width="match_parent" android:layout_height="0.5dp" android:background="#737373" /&gt; android:layout_width=...

    android layout 按比例布局的代码

    为了创建比例大小的子View,可以将LinearLayout的宽度和...对于LinearLayout的几个子View,将它们的宽度都定义为0,android:layout_width=”0dip”,然后使用layout_weight 为每个View指定宽度比例,本例为每个TextVie

    Android布局.rar

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

    Android布局之LinearLayout线性布局

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

    【Android Studio代码】线性布局

    用Android Studio 2.3.3做的线性布局例子,主要用到的标签有:&lt;LinearLayout&gt;&lt;/LinearLayout&gt;;主要用到的设置有:android:orientation="horizontal"、android:layout_weight="1"。

Global site tag (gtag.js) - Google Analytics