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>

  

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

Android添加布局和按键的更多相关文章

  1. Android添加新按键

    1.前言 在Android开发中可能会遇到添加新的按键的需求,本文将简单介绍如何在Android系统中完成一个新的按键的添加. 当系统有新的按键需要添加时,Linux内核下的键码到Android系统中 ...

  2. Android动画效果之自定义ViewGroup添加布局动画

    前言: 前面几篇文章介绍了补间动画.逐帧动画.属性动画,大部分都是针对View来实现的动画,那么该如何为了一个ViewGroup添加动画呢?今天结合自定义ViewGroup来学习一下布局动画.本文将通 ...

  3. Android 添加键值并上报从驱动到上层

    转载:https://blog.csdn.net/weixin_43854010/article/details/94390803 Android 添加键值并上报从驱动到上层 平台 :RK3288 O ...

  4. 【腾讯Bugly干货分享】Android动态布局入门及NinePatchChunk解密

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/57c7ff5d53bbcffd68c64411 作者:黄进——QQ音乐团队 摆脱 ...

  5. Xamarin.Android之布局文件智能提示问题

    一.前言 看到有人问关于xamarin.android的布局没智能提示问题(VS 2015),当然,写布局这东西没提示这是一件相对痛苦的事 ,所以这里就提供一个解决的方案! 二.解决方案 想要智能提示 ...

  6. Android基本布局

    android基本布局有三种:LinearLayout,RelativeLayout,FrameLayout. 一.LinearLayout 1,这是一种垂直布局(或者水平布局),可以通过下面这一句来 ...

  7. android layout布局属性

    参考:http://blog.csdn.net/msmile_my/article/details/9018775 第一类:属性值 true或者 false           android:lay ...

  8. Android 优化布局层次结构

    前面介绍过使用HierarchyViewer和Android lint来优化我们的程序,这一篇算是总结性的,借助一个小例子来说用怎么优化应用布局.这个例子是android官网给出的,作者也当一把翻译. ...

  9. Android相对布局(RelativeLayout)

    Android相对布局(RelativeLayout) 备注:这里的视图和元素是等同的概念. RelativeLayout是一个允许子视图相对于其他兄弟视图或是父视图显示的视图组(通过ID指定).每个 ...

随机推荐

  1. springboot-@EventListener简单用法

    @EventListener简单描述 简化我们编写监听类的步骤,不需要再继承ApplicationListener接口去实现onApplicationEvent了. 例子: @Component pu ...

  2. Spring-boot-菜鸟-配置-简介

    SpringBoot使用一个全局的配置文件,配置文件名是固定的: •application.properties •application.yml 配置文件的作用:修改SpringBoot自动配置的默 ...

  3. Dubbo 推荐用什么协议?

    dubbo://(推荐) rmi:// hessian:// http:// webservice:// thrift:// memcached:// redis:// rest://

  4. Python - random库介绍

  5. MySQL碎片整理小节--实例演示

    MYSQL之磁盘碎片整理 清澈,细流涓涓的爱 数据库引擎以InnoDB为主 1.磁盘碎片是什么 ​ InnoDB表的数据存储在页中,每个页可以存放多条记录,这些记录以树形结构组织,这棵树称为B+树. ...

  6. C语言常用字符串函数

    string.h头文件中常用的函数 C 库函数 - strcat() char *strcat(char *dest, const char *src) 把 src 所指向的字符串追加到 dest 所 ...

  7. 电源PCB布板的10个基本法则

    电容模型 电容并联高频特性 电感模型 电感特性 镜象面概念 高频交流电流环路 过孔 (VIA) 的例子 PCB板层分割 降压式(BUCK)电源:功率部分电流和电压波形 降压式电源排版差的例子 电路等效 ...

  8. d面试题汇总

    HTML Doctype作用,HTML5 为什么只需要写<!DOCTYPE HTML>? html5有哪些新特性?移除了哪些元素? 简述一下你对HTML语义化的理解? 行内元素有哪些,块级 ...

  9. 推荐一个用于压缩图片的JS插件:localResizeIMG

    惯例,先贴传送门:https://github.com/think2011/localResizeIMG 首先说到,为嘛要压缩图片,这需求一般出现在需要上传照片(尤其是移动端)的情况下,现在手机拍出来 ...

  10. python实战----Todo清单续写

    添加分页功能 第一步:是对视图函数的改写,通过查询数据库数据,进行分页显示 # 修改清单显示的视图函数 @app.route('/list/') @app.route('/list/<int:p ...