mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
個人BLOG
it developer
  1. Main page
  2. dev
  3. Main content

android layout_weight讲解

2012-02-04 92hotness 0likes 0comments

在网上看了一些对Layout_weight的讲解,有些说的比较片面,只列举了一种情况,然后自己通过实验和一些比较好的文章总结了一下,特此记录下来,以备以后所用。Layout_weight是线性布局,也就是LinearLayout里面用到的,下面通过实验来看这个Layout_weight的特性。


1.当控件的属性android:layout_width="fill_parent"时,布局文件如下:




Xml代码

<?xml version="1.0" encoding="utf-8"?>  


  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:orientation="horizontal" android:layout_width="fill_parent"  
  3.     android:layout_height="fill_parent">  
  4.     <Button android:layout_width="fill_parent"  
  5.         android:layout_height="wrap_content" android:layout_weight="1"  
  6.         android:text="Button1" />  
  7.     <Button android:layout_width="fill_parent"  
  8.         android:layout_height="wrap_content" android:layout_weight="2"  
  9.         android:text="Button2" />  
  10. </LinearLayout>  
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
android:text="Button1" />
<Button android:layout_width="fill_parent"
android:layout_height="wrap_conten

Tag: Nothing
Last updated:2012-02-04

mikebai

This person is a lazy dog and has left nothing

Like
< Last article
Next article >

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang