安卓app开发-05-Android xml布局详细介绍

本文详细介绍了Android XML布局,包括LinearLayout、RelativeLayout、FrameLayout、AbsoluteLayout和TableLayout。讲解了各种布局的特点和使用场景,提供了实例代码,并提到了布局参数的重要性和使用技巧。
摘要由CSDN通过智能技术生成
                       

安卓app开发-05-Android xml布局详细介绍

  • 虽然说有 墨刀,墨客 这些图形化开发工具来做 Android 的界面设计,但是我们还是离不开要去学习做安卓原生app,学习 xml 布局还是必要的

(1)准备

  • 首先我们要了解 android 到底有那些布局,和每个布局类型的区别
  • 学习时最好打开 Android Studio 打开 xml 文件对应看一下
  • 配置参数的详细含义不用着急全部理解,放在文章后面,可收藏做查阅【可通过目录跳转】

(2)学习目标

  • 学习下xml的布局文件具体写法。这一节我们要绘制如下图所示的界面
    在这里插入图片描述

(3)线性布局 LinearLayout

  • 线性布局分两种。一种是水平布局,一种是垂直布局。下面我们根据上图举例子
  • 上图代码:
<?xml version="1.0" encoding="utf-8"?><LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <TextView android:layout_height="wrap_content" android:text="@string/note_title"  android:layout_width="wrap_content" android:padding="10dp"></TextView> <LinearLayout android:layout_height="fill_parent"  android:layout_width="fill_parent" android:layout_weight="1">  <EditText android:id="@+id/EditText02" android:layout_width="fill_parent"   android:layout_height="fill_parent" android:gravity="left"   android:hint="@string/edithint"></EditText> </LinearLayout> <LinearLayout android:layout_height="fill_parent"  android:layout_width="fill_parent" android:layout_weight="2"  android:gravity="center"  android:orientation="horizontal">     <ImageButton android:id="@+id/ImageButton01" android:layout_width="72dp" android:layout_height="72dp" android:src="@drawable/sketchy_paper_003" android:layout_margin="3dp"></ImageButton> <ImageButton android:id="@+id/ImageButton02" android:layout_width="72dp" android:layout_height="72dp" android:src="@drawable/sketchy_paper_004" android:layout_margin="3dp"></ImageButton> <ImageButton android:id="@+id/ImageButton03" android:layout_width="72dp" android:layout_height="72dp" android:src="@drawable/sketchy_paper_007" android:layout_margin="3dp"></ImageButton> <ImageButton android:id="@+id/ImageButton04" android:layout_width="72dp" android:layout_height="72dp" android:src="@drawable/sketchy_paper_011" android:layout_margin="3dp"></ImageButton> </LinearLayout> </LinearLayout> 
  
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 可以看到,上图是由三部分组成。在大的LinearLayout从上而下垂直分布着三个内容:TextView,LinearLayout,LinearLayout。所以总体的 LinearLayout 是垂直布局
  • 下面我们来看水平布局
  • 其实就是上图中的最下面那个 LinearLayout。四个图标平行排列。
    android:orientation=“horizontal”

(4)相对布局 RelativeLayout

  • 这个布局相对简单一点。一般来讲利用ADT自己拖放按钮就可以。基本上可以随意布局。如下图所示
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值