Android添加布局和按键

Android布局方式分为

    1.LinearLayout (线性布局)

    2.ConstraintLayout (约束布局)

    3.FrameLayout (帧布局)

    4.TableLayout (表格布局)

    5.RecyclerView (循环使徒)

我拿LinearLayout 线性布局来做演示,推荐书籍 《基于android studio的app案列教程(第2版)—宋三华》 讲的很详细,很好理解,没有基础也能看。 

首先:找到app下的activity_main.xml,双击打开,

我们将布局方式改为LinearLayout ,同时使用垂直方向布局(vertical),水平方向布局为horizontal。

这时候我们得到了一个空白的线性布局,这时候就可以在布局中添加按键(设置背景看我的文章:Android添加背景和设置app图标

一行里面添加两个Button按键,添加三个按键就是在LinearLayout之中含有三个Button

将以下代码保存到activity_main.xml可直接使用,添加背景还需要自己配置 Android添加背景和设置app图标

<?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"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="270dp">
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="85dp">
<Button
android:id="@+id/button1"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="馒头1"
android:textSize="20dp">
</Button>
<Button
android:id="@+id/button2"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="馒头2"
android:textSize="20dp"> </Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="85dp">
<Button
android:id="@+id/button3"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="馒头3"
android:textSize="20dp"
>
</Button>
<Button
android:id="@+id/button4"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="馒头4"
android:textSize="20dp"> </Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="85dp">
<Button
android:id="@+id/button5"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="馒头5"
android:textSize="20dp">
</Button>
<Button
android:id="@+id/button6"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="馒头6"
android:textSize="20dp"> </Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="85dp">
<Button
android:id="@+id/button7"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="馒头7"
android:textSize="20dp">
</Button>
<Button
android:id="@+id/button8"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="馒头8"
android:textSize="20dp"> </Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="85dp">
<Button
android:id="@+id/button9"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="馒头9"
android:textSize="20dp">
</Button>
<Button
android:id="@+id/button10"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="馒头10"
android:textSize="20dp"> </Button>
</LinearLayout> </LinearLayout>

  

很简单,通过布局可以随着你的想法,添加不同的组件来构造你想要的模型

最新文章

  1. 查看IIS哪个应用程序池占用CPU过高
  2. 往sql数据库表中添加字段
  3. mixed content 混合内容
  4. HDU 4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)
  5. 剑指OFFER之二维数组中的查找(九度OJ1384)
  6. Underscore.js(1.7.0) 中文文档 Underscore.js 入门
  7. 日志的艺术(The art of logging)
  8. Android Bootloader LittleKernel的两篇文章
  9. Nessus更新到8.3.0
  10. Android进程间通信IPC
  11. 分享一个可以把 iOS/Android 应用的下载链接合成一个二维码的工具
  12. COMBIN14简单应用
  13. preg_match(): Compilation failed: character value in \x{} or \o{} is too large at offset 8
  14. hdu5358 推公式+在一个区间内的尺取+枚举法
  15. Spring Boot(一):入门篇
  16. PxCook 像素大厨 标注切图,一起搞定!专注设计本质
  17. wordvec_词的相似度
  18. 使用 git post-receive 钩子部署服务端代码
  19. 服务器安装LNMP及构建个人站点
  20. go 函数的作用域及可见性

热门文章

  1. memcached 如何处理容错的?
  2. 什么是消费者驱动的合同(CDC)?
  3. vue3在组件上使用v-model
  4. C语言之开发流程(知识点7)
  5. 基本类型数组转List
  6. leetcode_两数相加
  7. BMZCTF simple_pop
  8. scanf()格式化输入
  9. React 和 ES6 工作流之 Webpack的使用(第六部分)
  10. 移动端城市定位,城市区域代码adcode