学习LinearLayout布局

   LinearLayout布局其实当我们创建第一个安卓程序的时候就已经看见了,它就在main.xml文件中就已经出现了,那它究竟是什么呢?用简单直译它就是线性布局,它是一个最常见的布局方式,它可以分为水平线性布局和垂直线性布局两种,通过android:orientation属性可以改变布局的方向。其实这个布局说那么多还不如写各程序来看的直接,创建一个安卓程序,写下main.xml里面的代码,其它不用变就可以测试看一下简单的一些例子:


main.xml布局文件内容:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<LinearLayout 
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content">
  
  <EditText 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
  />
    
</LinearLayout>
<LinearLayout 
 android:orientation="horizontal"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
   android:gravity="right">
  <Button 
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="确定"
  />
  
     <Button 
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="消失"
  />
  
</LinearLayout>
 
 <LinearLayout 
 android:orientation="horizontal"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
     <TextView 
     android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="3"
      android:background="#000fff"/>
     <TextView 
     android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1"
      android:background="#ff0000"/>
   
</LinearLayout>
 
 
</LinearLayout>
虽然不止这些,但也不可能一个小小的例子就可以让我们应用自如,还需要我们多加尝试。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值