LinearLayout初学者练习



  LinearLayout线性布局):布局,就是把控件按照某种特定的方式排序,控件之间的关系独立的。而线性布局分为两个方向:横向(Android:orientation="horizontal")或纵向(android:orientation="vertical").

1.

android布局--Android fill_parent、wrap_content和match_parent的区别

三个属性都用来适应视图的水平或垂直大小,一个以视图的内容或尺寸为基础的布局比精确地指定视图范围更加方便。

1)fill_parent

设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间。这跟Windows控件的dockstyle属性大体一致。设置一个顶部布局或控件为fill_parent将强制性让它布满整个屏幕。

2) wrap_content

设置一个视图的尺寸为wrap_content将强制性地使视图扩展以显示全部内容。以TextView和ImageView控件为例,设置为wrap_content将完整显示其内部的文本和图像。布局元素将根据内容更改大小。设置一个视图的尺寸为wrap_content大体等同于设置Windows控件的Autosize属性为True。

3)match_parent
   Android2.2中match_parent和fill_parent是一个意思 .两个参数意思一样,match_parent更贴切,于是从2.2开始两个词都可以用。那么如果考虑低版本的使用情况你就需要用fill_parent了

//转自:http://www.cnblogs.com/nikyxxx/archive/2012/06/15/2551390.html。


2.    0dip的用法

    布局中常见:layout_height="0dip"  或者 layout_width="0dip"   

     这里的意思是不是用具体的数值来计算高度或者宽度,而是和layout_weight 一起来使用的。经常会有这样的写法: 同一个LinearLayout  (假设是横向的) 中 有几个view ,但是都不指定其具体的宽度,而是使用 layout_weight 参数来指定这几个view所占的比例。每个view所占的宽度的比例是自己的layout_weight 值和总的layout_weight的总和的比值。

例如:

       android:layout_width="match_parent"

       android:layout_height="wrap_content"

       android:orientation="horizontal"

       android:background="@android:drawable/bottom_bar">

       

           android:layout_width="0dip"

           android:layout_height="match_parent"

           android:layout_weight="1"/>

       

           android:layout_width="0dip"

           android:layout_height="wrap_content"

            android:layout_weight="2"

           android:layout_marginTop="5dip"

           android:text="@string/remove_account_label" />

       

            android:layout_width="0dip"

           android:layout_height="match_parent"

           android:layout_weight="1"/>

   

这几个View宽度的的比例便是1:2:1

//转自:http://www.xuebuyuan.com/1111975.html。

3.


模仿设计小米计算机页面布局:



红色标记的是注意点


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

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

   
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >//注意括号的位置

       
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="c"
            android:textColor="#FCD648"/>         //设置标题颜色
        


                    android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="DEL"/>
        

                    android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="÷" />

                    android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="×" />
   


            android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

                    android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="7" />

                    android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="8" />

                    android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="9" />

                    android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="-" />
   

            android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

                    android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="4" />

                    android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="5" />

                    android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="6" />

                    android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="+" />
   

          android:layout_width="fill_parent"
      android:layout_height="wrap_content"
        android:orientation="horizontal" >

                android:orientation="vertical"     
        android:layout_width="0dip"
        android:layout_weight="3"
        android:layout_height="wrap_content">

                                     android:layout_width="fill_parent"
                         android:layout_height="wrap_content"
                         android:orientation="horizontal">

                                    android:layout_width="0dip"
                   android:layout_weight="1"
                    android:layout_height="wrap_content"
                   
                    android:text="1" />

                                    android:layout_width="0dip"
                     android:layout_weight="1"
                    android:layout_height="wrap_content"
                   
                    android:text="2" />

                                    android:layout_width="0dip"
                       android:layout_weight="1"
                    android:layout_height="wrap_content"
                 
                    android:text="3" />
           

                            android:layout_width="fill_parent"
                android:layout_height="wrap_content" >

                                    android:layout_width="0dip"
                    android:layout_weight="2"
                    android:layout_height="wrap_content"
          
                    android:text="0" />

                                    android:layout_width="0dip"
                     android:layout_weight="1"
                    android:layout_height="wrap_content"
                   
                    android:text="." />
        
           
            
           
       

                     android:text="="
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="fill_parent"
           
            android:background="#FCD648"  //设置背景
            android:gravity="bottom|right"、、//设置标题居右下
            
          
           
        />
        
        
        
        
        
   
        
        
        
        
        
        
        
        

   

效果图:






更多相关文章

  1. Android7关闭selinux(设置为Permissive模式)
  2. EditText属性详解
  3. Android中ExpandableListView控件基本使用
  4. Android的用户界面
  5. Android--学习笔记--02--AndroidStudio的设置
  6. android评分条RatingBar自定义设置
  7. android中文api(89)――ViewManager
  8. android 硬件加速后webview闪烁问题
  9. Android(安卓)UI测量、布局、绘制过程探究

随机推荐

  1. Android判断定位功能是否开启
  2. Android:安装APK包以后系统文件目录的变
  3. android 之 handler
  4. Java集合框架——Android中的ArrayList源
  5. Android Studio导入项目的gradle与studio
  6. Android Calendar一闪而过 无法创建event
  7. invalid resource directory name
  8. Android的SQLite使用实例
  9. Android 进程生命周期(Process Lifecycle
  10. 扔掉USB线,无需无线路由器,利用笔记本电脑(W