设为首页 加入收藏

TOP

Android开发5大布局方式详解(二)
2017-10-13 10:35:47 】 浏览:9825
Tags:Android 开发 布局 方式 详解
p;     android:layout_height="wrap_content" 
  •             android:layout_width="wrap_content" 
  •             android:text="取消" 
  •             />    
  •      </LinearLayout> 
  • </LinearLayout> 
  • 第二个实例

    ①效果图:

     

     

    ②核心代码:

    mian.xml
     
    1. <?xml version="1.0" encoding="utf-8"?> 
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    3.     android:orientation="vertical" android:layout_width="fill_parent" 
    4.     android:layout_height="fill_parent"> 
    5.  
    6.     <LinearLayout 
    7.     android:orientation="horizontal" 
    8.     android:layout_width="fill_parent" 
    9.     android:layout_height="fill_parent" 
    10.     android:layout_weight="1"> 
    11.       
    12.     <TextView 
    13.         android:text="red" 
    14.         android:gravity="center_horizontal" 
    15.         android:background="#aa0000" 
    16.         android:layout_width="wrap_content" 
    17.         android:layout_height="fill_parent" 
    18.         android:layout_weight="1" 
    19.         /> 
    20.      <!--android:gravity="center_horizontal"水平居中 -->   
    21.      <!--layout_weight属性以控制各个控件在布局中的相对大小。layout_weight属性是一个非负整数值。  
    22.          线性布局会根据该控件layout_weight值与其所处布局中所有控件layout_weight值之和的比值为该控件分配占用的区域。  
    23.         例如,在水平布局的LinearLayout中有两个Button,这两个Button的layout_weight属性值都为1,  
    24.         那么这两个按钮都会被拉伸到整个屏幕宽度的一半。如果layout_weight指为0,控件会按原大小显示,不会被拉伸;  
    25.         对于其余layout_weight属性值大于0的控件,系统将会减去layout_weight属性值为0的控件的宽度或者高度,  
    26.         再用剩余的宽度或高度按相应的比例来分配每一个控件显示的宽度或高度--> 
    27.     <TextView 
    28.         android:text="Teal" 
    29.         android:gravity="center_horizontal" 
    30.   &nb
    首页 上一页 1 2 3 4 5 6 7 下一页 尾页 2/7/7
    】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
    上一篇ListFragment的使用 下一篇Android快乐贪吃蛇游戏实战项目开..

    最新文章

    热门文章

    Hot 文章

    Python

    C 语言

    C++基础

    大数据基础

    linux编程基础

    C/C++面试题目