[站点选择] 服务热线13396739763 13136206268 在线咨询 留言/需求提交

Android App开发:最常见的线性布局

    Android App开发中有5种常见的布局方式,包括线性布局,帧布局,表格布局,相对布局,绝对布局。今天我们来介绍最常见的一种布局方式,那就是线性布局。

 

    线性布局是Android开发中最常见的一种布局方式,它是按照垂直或者水平方向来布局,通过“android:orientation”属性可以设置线性布局的方向。属性值有垂直(vertical)和水平(horizontal)两种。

 

Android App开发:最常见的线性布局

 

    LinearLayout属性中android:orientation为设置线性布局当其="vertical"时,为 垂直线性布局,当其="horizontal"时,为水平线性布局,不管是水平还是垂直线性布局一行(列)只能放置一个控件。

 

    线性布局代表类是(LinearLayout),LinearLayout不仅可以控制个组件横向排列,也可以纵向排列(通过android:orientation属性控制),

     注意点:android中的LinearLayout使用时,当一行填满时候,不会自动换行,多出的将不会被显示。

 

    android:orientation:可以设置布局的方向,android:gravity:用来控制组件的对齐方式,layout_weight:控制各个组件在布局中的相对大小。


    垂直线性布局代码如下:

 

    <?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
 
    <EditText  
        android:layout_width="100dp" 
        android:layout_height="wrap_content" 
         
        /> 
     
    <Button  
        android:layout_width="100dp" 
        android:layout_height="wrap_content" 
        android:text="Button1"/> 
 
    <Button  
        android:layout_width="100dp" 
        android:layout_height="wrap_content" 
        android:text="button2"/> 
 
</LinearLayout> 

 

    水平线性布局代码如下:

 

    <?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 
     
    <EditText  
        android:layout_width="100dp" 
        android:layout_height="wrap_content" 
        /> 
     
    <Button  
        android:layout_width="100dp" 
        android:layout_height="wrap_content" 
        android:text="Button1"/> 
 
    <Button  
        android:layout_width="100dp" 
        android:layout_height="wrap_content" 
        android:text="button2"/> 
 
</LinearLayout> 

 

丹徒App开发:http://qianxx.com/

Android开发:http://qianxx.com/andriod/

声明:文章来源于互联网!
 

 嘉兴方案网
 13396739763 13136206268 (节假日均可拨打) 0573-83698396 (周一至周六可拨打)


售前咨询QQ:点击这里给我发消息    点击这里给我发消息


技术支持QQ:点击这里给我发消息

所在地址: 浙江省嘉兴市城南路1539号创业大厦


网址:www.nice-solution.com

  网站建设 / 网络推广 / APP开发 / 软件定制 / 网站设计/网站制作/微网站制作/微网站建设/微网站设计/丹徒微网站建设/微网站
 专业做高端网站建设网站设计网站改版网站维护微网站建设微网站制作丹徒网站建设丹徒网站设计丹徒网站制作软件开发APP应用丹徒微官网制作动画制作域名注册空间托管企业邮箱注册样本宣传册印刷制作400电话做网站业务

友情站点

>