zoukankan      html  css  js  c++  java
  • Android LinearLayout深入学习

    接触安卓有两个月的时间了,一直觉得LinearLayout有什么好学的,觉得想做比较复杂的应用UI都得是使用RelativeLayout才好,最近做项目看了别人的代码后才发现,线性布局在做复杂项目的时候,一样是非常重要!

    1、layout_width:这个变量可以用来按比例摆放几个控件

    2、layout_gravity:用来做控件对齐使用

    3、多层Layout的嵌套,比如竖直分布中,每个又是水平布局,水平分布中又可以嵌套垂直布局,经过一些简单的组合,就可以做出非常漂亮、规法的界面,实行起来比使用相对布局更好调整。

    下面这个例子实现了竖直和水平、竖直布局的结合。

    效果图如下:

    程序实现代码:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        
        <FrameLayout 
            android:id="@+id/fl1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"  
            android:background="#00FF00"      
            >
            <ImageView 
                android:id="@+id/imageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#00000000"
                />
            <TextView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="中"
                android:layout_gravity="center"
                />
            
            
        </FrameLayout>
        
        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="100dp"     
            >
            
            <LinearLayout 
            android:layout_width="0dp"
            android:layout_height="100dp"
            android:layout_weight="1"        
            android:orientation="vertical"        
                >
                
            <Button 
                   android:layout_width="match_parent"
                   android:layout_height="60dp"
                   android:layout_marginTop="10dp"
                  android:layout_marginRight="15dp"
                  android:layout_marginLeft="15dp"
                   />
            <TextView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="按钮1"            
                android:layout_gravity="center"
                />
                        
            </LinearLayout>
            
            
           <LinearLayout 
            android:layout_width="0dp"
            android:layout_height="100dp"
            android:layout_weight="1"
             
            android:orientation="vertical"     
            
                >
                
            <Button 
                   android:layout_width="match_parent"
                   android:layout_height="60dp"
                   android:layout_marginTop="10dp"  
                  android:layout_marginRight="15dp"
                  android:layout_marginLeft="15dp"
                   />
                    <TextView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="按钮2"            
                android:layout_gravity="center"
                />
                
            </LinearLayout>
            
           <LinearLayout 
            android:layout_width="0dp"
            android:layout_height="100dp"
            android:layout_weight="1"
            
            android:orientation="vertical"
            
                >
            <Button 
                   android:layout_width="match_parent"
                   android:layout_height="60dp"
                   android:layout_marginTop="10dp"
                  android:layout_marginRight="15dp"
                  android:layout_marginLeft="15dp"
                   />
                    <TextView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="按钮3"            
                android:layout_gravity="center"
                />
                
            </LinearLayout>
    
            
            
        </LinearLayout>
        
    
        
    
    </LinearLayout>
  • 相关阅读:
    Native Boot 从一个 VHD 引导系统的相关说明
    bind()函数的深入理解及两种兼容方法分析
    四、CentOS 6.5 上传和安装Nginx
    jQuery 常见操作实现方式
    “贷券” 信贷系统
    注册 Ironic 裸金属节点并部署裸金属实例
    hover()方法
    Uncaught SyntaxError: Inline Babel script: Unexpected token
    Uncaught Error: The `style` prop expects a mapping from style properties to values, not a string
    jquery bind事件
  • 原文地址:https://www.cnblogs.com/wll-zju/p/4242837.html
Copyright © 2011-2022 走看看