这篇文章主要是介绍线性布局和约束布局的一些常用属性,以及textview的一些常用的用法。主要还是得多实践。

文章目录

  • (1)线性布局
  • (2)相对布局
  • (3)小结

(1)线性布局

主要的属性:如代码所示,在代码中解释属性。

<?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"//设置布局是垂直布局还是横向布局android:paddingTop="20dp"//设置布局管理器内组件距离父物体顶部的距离><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="hello world "></TextView><LinearLayoutandroid:layout_width="200dp"android:layout_height="200dp"android:padding="20dp"android:orientation="vertical"android:gravity="center"//设置布局管理器内的组件的对齐方向><Viewandroid:layout_height="50dp"android:layout_width="50dp"android:layout_weight="1"android:background="@color/black"></View><Viewandroid:layout_height="50dp"android:layout_width="50dp"android:layout_weight="1"android:background="@color/black"android:layout_marginTop="30dp"//设置距离上个组件top端的位置></View></LinearLayout></LinearLayout>

我们通过这段代码中不难发现,其实margin和padding属性是有些类似的,并且都可以设置上下左右的距离,我们可以记住大概的意思就可以了,主要还是得多实践,多实践,多实践,重要的事说三遍!!!

(2)相对布局

相对布局我们也采用在代码中解释属性,来带大家了解他的一些属性

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:paddingTop="20dp"><Buttonandroid:id="@+id/btm"//每个组件都设置一个属于自己的id,然后布局的话我们可以减少嵌套布局,可以根据周围的组件来进行布局。android:layout_width="100dp"android:layout_height="100dp"android:layout_centerInParent="true"android:text="Button"></Button><RelativeLayoutandroid:layout_width="300dp"android:layout_height="300dp"android:layout_below="@id/btm"android:layout_marginTop="10dp"android:background="#ffff00"android:gravity="center"><TextViewandroid:id="@+id/t1"android:layout_width="100dp"android:layout_height="100dp"android:text="textview1"android:textSize="20dp"></TextView><TextViewandroid:id="@+id/t2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@id/t1"android:layout_marginTop="10dp"android:text="textview1"></TextView><TextViewandroid:id="@+id/t3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@id/t2"android:layout_marginTop="10dp"android:text="textview1"></TextView></RelativeLayout></RelativeLayout>

对相对布局的看法:最大的区别就是可以给每个组件一个id,可以根据周围的控件来进行布局,当然,线性布局和相对布局之间是可以相互嵌套的,可以更灵活吧,这里可能对相对布局介绍的简单了点,我们后续会用到什么,再补充进来。

(3)小结

这两种布局可能没有约束布局好用,个人认为,但是网上的老师,和学校的老师都说,这两种布局是现在常用的两种,我们就先学好这两种布局,用好这两种布局,到时候上手约束布局就会很容易了(约束布局yyds),我在下个礼拜准备用这两个布局写一个界面,可能会用到更多的东西,尽请期待!

Android小结(1)相关推荐

  1. android小结2(诚迈时期)

    //起模拟器 cd /work/hid-huawei;source build/envsetup.sh;lunch 1;emulator -skindir development/emulator/s ...

  2. android 小结1(诚迈时期)

    //重定向svn服务器. svn switch --relocate svn://192.168.10.202/huawei_hid/WeatherWidget svn://192.168.10.20 ...

  3. Android 常用开源框架源码解析 系列 (九)dagger2 呆哥兔 依赖注入库

    一.前言 依赖注入定义 目标类中所依赖的其他的类的初始化过程,不是通过手动编码的方式创建的. 是将其他的类已经初始化好的实例自动注入的目标类中. "依赖注入"也是面向对象编程的 设 ...

  4. android apk签名工具_关于keytool和jarsigner工具签名的使用小结

    在我们日常Android应用开发中,我们都要对我们开发的apk做签名处理,或者加固,增强我们apk的安全性,防止被逆向反编译,在apk签名这块,我们一般采用JDK自动工具来签名,下面就对相关工具做个简 ...

  5. Android 4.2.2原生Launcher修改使之可以运行过程小结

    Android 4.2.2原生Launcher修改使之可以运行过程小结 要想让原生的Launcher代码能运行起来,主要有三个问题: 1.Launcher类编译不过的问题:com.android.co ...

  6. 《深入理解Android:卷III A》一一2.4本章小结

    本节书摘来华章计算机出版社<深入理解Android:卷III A>一书中的第2章,第2.4节,作者:张大伟 更多章节内容可以访问云栖社区"华章计算机"公众号查看.1 2 ...

  7. vlc android 编译 mac,在Mac中编译vlc-android小结

    在Mac中编译vlc-android小结 在Mac中编译vlc-android小结 VLC  CodeSource https://code.videolan.org/explore This pag ...

  8. android accessibility 模拟键盘事件_H5 键盘兼容性小结

    在 H5 项目中,我们会经常遇到页面中存在单个甚至多个 input/textarea 输入框与底部固定元素的布局情况.在 input/textarea 输入框获取焦点时,会自动触发键盘弹起,而键盘弹出 ...

  9. android studio项目总结,android studio 3.0 升级 项目遇到的问题及更改思路(问题小结)...

    Android Studio从3.0版本新增了许多功能,当然首当其冲就是从3.0版本新增了对 Kotlin 开发语言的支持,除此之外还有其他一些新功能,例如:Android Profiler (其中包 ...

最新文章

  1. Hinton等人新研究:如何更好地测量神经网络表示相似性
  2. codeforces425C
  3. 谷歌浏览器异步请求后台session变了_session打爆面试官
  4. 搭建Jenkins+Sonarqub+Mysql+Android(上篇)
  5. CCNP精粹系列之十八--路由映射实战二,博主推荐文章
  6. 【php数组函数序列】之prev() - 移动数组内部指针到上一个元素的位置,并返回该元素值...
  7. TensorFlow第三步 :单层网络-Mnist手写数字识别
  8. 数据库的四大特性以及事务的隔离级别
  9. linux命令 三大利器,awk、grep、sed是linux操作文本的三大利器,也是必须掌握的linux命令之一...
  10. java常用英语单词大全(一)
  11. android摇骰子动画,Android实现微信摇骰子游戏
  12. stm32——自定义HID设备
  13. 果园篱笆c语言算法,凸包问题(果园篱笆)
  14. zabbix监控软件介绍<一>
  15. 直播系统---从直播答题看SEI帧的原理和作用
  16. postgresql设置自动更新时间方法
  17. ping unknown host问题怎么解决?
  18. 黄淮学院计算机类专业属于几本,黄淮学院是几本院校
  19. 工商银行考试计算机知识,【必读】工商银行考试内容及复习方法
  20. dedecms织梦调用指定顶级栏目名称的方法

热门文章

  1. apache php 调优_Apache的性能优化(二)
  2. bulkwrite 批量插入_SQL SERVER 使用BULK Insert将txt文件中的数据批量插入表中(1)
  3. sybase isql 重启_学习这篇文章,搭建Sybase数据库不再是难题!
  4. python 笔试题 英方_经典算法题 :找字符串中的逆序对(百度笔试题)
  5. python股票涨势_stock
  6. python第三周笔记_Python第三周 学习笔记(1)
  7. nebual的图数据结构
  8. Exception in thread main java.lang.NoSuchMethodError: scala.Predef$
  9. python官网下载哪个版本好玩_Python官网不同版本的下载
  10. 服务器怎么查看性能,查看服务器进程性能查看