Android添加布局和按键
Android添加布局和按键
Android布局方式分为
1.LinearLayout (线性布局)
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添加布局和按键的更多相关文章
- Android添加新按键
1.前言 在Android开发中可能会遇到添加新的按键的需求,本文将简单介绍如何在Android系统中完成一个新的按键的添加. 当系统有新的按键需要添加时,Linux内核下的键码到Android系统中 ...
- Android动画效果之自定义ViewGroup添加布局动画
前言: 前面几篇文章介绍了补间动画.逐帧动画.属性动画,大部分都是针对View来实现的动画,那么该如何为了一个ViewGroup添加动画呢?今天结合自定义ViewGroup来学习一下布局动画.本文将通 ...
- Android 添加键值并上报从驱动到上层
转载:https://blog.csdn.net/weixin_43854010/article/details/94390803 Android 添加键值并上报从驱动到上层 平台 :RK3288 O ...
- 【腾讯Bugly干货分享】Android动态布局入门及NinePatchChunk解密
本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/57c7ff5d53bbcffd68c64411 作者:黄进——QQ音乐团队 摆脱 ...
- Xamarin.Android之布局文件智能提示问题
一.前言 看到有人问关于xamarin.android的布局没智能提示问题(VS 2015),当然,写布局这东西没提示这是一件相对痛苦的事 ,所以这里就提供一个解决的方案! 二.解决方案 想要智能提示 ...
- Android基本布局
android基本布局有三种:LinearLayout,RelativeLayout,FrameLayout. 一.LinearLayout 1,这是一种垂直布局(或者水平布局),可以通过下面这一句来 ...
- android layout布局属性
参考:http://blog.csdn.net/msmile_my/article/details/9018775 第一类:属性值 true或者 false android:lay ...
- Android 优化布局层次结构
前面介绍过使用HierarchyViewer和Android lint来优化我们的程序,这一篇算是总结性的,借助一个小例子来说用怎么优化应用布局.这个例子是android官网给出的,作者也当一把翻译. ...
- Android相对布局(RelativeLayout)
Android相对布局(RelativeLayout) 备注:这里的视图和元素是等同的概念. RelativeLayout是一个允许子视图相对于其他兄弟视图或是父视图显示的视图组(通过ID指定).每个 ...
随机推荐
- java-iov概念
Ioc-Inversion of Control 即"控制反转",不是什么技术,而是一种设计思想.在Java开发中,Ioc意味着将你设计好的对象交给容器控制,而不是传统的在你的对象 ...
- 说出 5 条 IO 的最佳实践?
IO 对 Java 应用的性能非常重要.理想情况下,你不应该在你应用的关键路径上 避免 IO 操作.下面是一些你应该遵循的 Java IO 最佳实践: a)使用有缓冲区的 IO 类,而不要单独读取字节 ...
- vmware 磁盘清理---还原虚拟机硬盘大小
linux host: 1.使用dd命令将客户机未使用的磁盘空间用0填满 cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill ...
- 学习RabbitMQ(五)
消息中间件就是在消息的传输过程中保存消息的容器.消息中间件再将消息从它的源中继到它的目标时充当中间人的作用.队列的主要目的是提供路由并保证消息的传递:如果发送消息时接收者不可用,消息队列会保留消息,直 ...
- ctfhub 双写绕过 文件头检查
双写绕过 进入环境 上传一句话木马 上传路径感觉不对检查源代码 从此处可以看出需要双写绕过 使用bp抓包 此处这样修改即可双写绕过 使用蚁剑连接 即可找到flag 文件头检查 进入环境 上传一句话木马 ...
- 第 4 章 ROS运行管理
第 4 章 ROS运行管理 ROS是多进程(节点)的分布式框架,一个完整的ROS系统实现: 可能包含多台主机:每台主机上又有多个工作空间(workspace):每个的工作空间中又包含多个功能包(pac ...
- scanf()格式化输入
scanf();有种带[]的格式化输出方式 此格式控制符的基本格式为:%[scanfset] #include<stdio.h> int main() { char str[100] ; ...
- 关于css布局、居中的问题以及一些小技巧
CSS的两种经典布局 左右布局 一栏定宽,一栏自适应 <!-- html --> <div class="left">定宽</div> < ...
- css边距重叠的解决方案
** css防止边距重叠的方法 ** 今天整理了一下用css防止边距重叠的几种方法先假设一组dom结构 <div class="parent"> <div cla ...
- java中Object类是怎么回事,干嘛使的?举例说明!
Object类的作用:m a r k - t o- w i n: 在java中,因为所有的类都有共性,所以java的缔造者们把java设计成这样:所有的类都是Object类的直接或间接子 ...