当前位置: 首页 > news >正文

Android入门

下载Android studio,创建第一个项目
在这里插入图片描述
模板可以选择empty views Activity
在这里插入图片描述
在这个界面可以修改,使用语言,项目名字,存储路径以及适用版本
在这里插入图片描述
完成后,得到一个最初始的Android 项目,红色标记的两个文件,一个是负责逻辑的java文件,一个是负责界面设计的xml文件
在这里插入图片描述

布局文件以xml为后缀,主要使用,线性布局和相对布局,虽然也可以用图形拖拽的方式设计界面,但是细调还是要理解代码
以计算器的布局为例,
首先线性布局,多用嵌套,分为垂直和水平两种方向,设计一个计算器的思路是。如下设计就可以实现,两行,每行有三列button
<线性垂直分布>
<线性垂直分布>



</线性垂直分布>
<线性垂直分布>



</线性垂直分布>
</线性垂直分布>

<?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"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="154dp"android:orientation="vertical"><EditTextandroid:id="@+id/editTextText"android:layout_width="wrap_content"android:layout_height="72dp"android:layout_weight="1"android:ems="10"android:inputType="text"android:text="Name" /><TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="TextView" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="64dp"android:orientation="horizontal"><ImageButtonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:src="@drawable/ic_launcher_foreground"android:text="1" /><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="12dp"android:layout_weight="1"android:text="2" /><Buttonandroid:id="@+id/button3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="12dp"android:layout_weight="1"android:text="3" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="64dp"android:orientation="horizontal"><Buttonandroid:id="@+id/button4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="4" /><Buttonandroid:id="@+id/button5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="8dp"android:layout_weight="1"android:text="5" /><Buttonandroid:id="@+id/button6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="8dp"android:layout_weight="1"android:text="6" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="63dp"android:layout_marginTop="8dp"android:orientation="horizontal"><Buttonandroid:id="@+id/button7"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="7" /><Buttonandroid:id="@+id/button8"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="8dp"android:layout_weight="1"android:text="8" /><Buttonandroid:id="@+id/button0"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="8dp"android:layout_weight="1"android:text="9" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="63dp"android:layout_marginTop="8dp"android:orientation="horizontal"><Buttonandroid:id="@+id/button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="0" /><Buttonandroid:id="@+id/button10"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="8dp"android:layout_weight="1"android:text="+" /><Buttonandroid:id="@+id/button11"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="8dp"android:layout_weight="1"android:text="=" /></LinearLayout>
</LinearLayout>

如果使用相对布局,要确定谁在谁的上方或者下方

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/container"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="com.example.test.MainActivity"android:padding="15dp"android:layout_gravity="center"android:background="#111"><Buttonandroid:id="@+id/button4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button13"android:layout_alignBottom="@+id/button13"android:layout_toLeftOf="@+id/button2"android:background="#a10b39"android:padding="10dp"android:text="="android:textColor="#fff"android:textSize="10dp"android:layout_marginRight="3dp"/><Buttonandroid:id="@+id/button9"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button10"android:layout_alignBottom="@+id/button10"android:layout_alignLeft="@+id/button7"android:background="#666"android:padding="10dp"android:text="7"android:textColor="#fff"android:textSize="10dp"android:layout_marginRight="3dp"android:layout_width="wrap_content"android:layout_marginBottom="3dp"/><Buttonandroid:id="@+id/button11"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button10"android:layout_alignBottom="@+id/button10"android:layout_toRightOf="@+id/button13"android:background="#666"android:padding="10dp"android:text="9"android:textColor="#fff"android:textSize="10dp"android:layout_marginRight="3dp"android:layout_width="wrap_content"android:layout_marginBottom="3dp"/><Buttonandroid:id="@+id/button10"android:layout_height="wrap_content"android:layout_alignLeft="@+id/button18"android:layout_below="@+id/button17"android:background="#666"android:padding="10dp"android:text="8"android:textColor="#fff"android:textSize="10dp"android:layout_marginRight="3dp"android:layout_width="wrap_content"android:layout_marginBottom="3dp"/><Buttonandroid:id="@+id/button20"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/button14"android:layout_alignParentRight="true"android:background="#a10b39"android:padding="10dp"android:text="←"android:textColor="#fff"android:textSize="10dp"android:layout_marginBottom="3dp"/><Buttonandroid:id="@+id/button19"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button20"android:layout_alignBottom="@+id/button20"android:layout_toLeftOf="@+id/button20"android:background="#a10b39"android:padding="10dp"android:text="CE"android:textColor="#fff"android:textSize="10dp"android:layout_marginRight="3dp"android:layout_marginBottom="3dp"/><Buttonandroid:id="@+id/button18"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/button10"android:layout_toLeftOf="@+id/button11"android:background="#a10b39"android:padding="10dp"android:text="±"android:textColor="#fff"android:textSize="10dp"android:layout_marginRight="3dp"android:layout_marginBottom="3dp"/><Buttonandroid:id="@+id/button17"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_below="@+id/editText1"android:layout_marginTop="5dp"android:background="#a10b39"android:padding="10dp"android:text="√"android:textColor="#fff"android:textSize="10dp"android:layout_marginRight="3dp"android:layout_marginBottom="3dp" /><Buttonandroid:id="@+id/button14"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_below="@+id/button18"android:background="#d89218"android:padding="10dp"android:text="÷"android:textColor="#fff"android:textSize="10dp"android:layout_marginBottom="3dp" /><Buttonandroid:id="@+id/button7"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/button10"android:layout_toRightOf="@+id/button6"android:background="#666"android:padding="10dp"android:text="5"android:textColor="#fff"android:textSize="10dp"android:layout_marginBottom="3dp"android:layout_marginRight="3dp"/><Buttonandroid:id="@+id/button6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button7"android:layout_alignBottom="@+id/button7"android:layout_alignParentLeft="true"android:background="#666"android:padding="10dp"android:text="4"android:textColor="#fff"android:textSize="10dp"android:layout_marginRight="3dp"android:layout_marginBottom="3dp" /><Buttonandroid:id="@+id/button15"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button7"android:layout_alignBottom="@+id/button7"android:layout_alignParentRight="true"android:background="#d89218"android:padding="10dp"android:text="×"android:textColor="#fff"android:textSize="10dp"android:layout_marginBottom="3dp" /><Buttonandroid:id="@+id/button8"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button7"android:layout_alignBottom="@+id/button7"android:layout_toRightOf="@+id/button10"android:background="#666"android:padding="10dp"android:text="6"android:textColor="#fff"android:textSize="10dp"android:layout_marginBottom="3dp"android:layout_marginRight="3dp" /><Buttonandroid:id="@+id/button3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/button7"android:layout_toRightOf="@+id/button1"android:background="#666"android:padding="10dp"android:text="2"android:textColor="#fff"android:textSize="10dp"android:layout_marginBottom="3dp"android:layout_marginRight="3dp" /><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button3"android:layout_alignBottom="@+id/button3"android:layout_alignParentLeft="true"android:background="#666"android:padding="10dp"android:text="1"android:textColor="#fff"android:textSize="10dp"android:layout_marginBottom="3dp"android:layout_marginRight="3dp" /><Buttonandroid:id="@+id/button5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button3"android:layout_alignBottom="@+id/button3"android:layout_toRightOf="@+id/button7"android:background="#666"android:padding="10dp"android:text="3"android:textColor="#fff"android:textSize="10dp"android:layout_marginBottom="3dp"android:layout_marginRight="3dp"/><Buttonandroid:id="@+id/button16"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button5"android:layout_alignBottom="@+id/button5"android:layout_alignLeft="@+id/button15"android:background="#d89218"android:padding="10dp"android:text="-"android:textColor="#fff"android:textSize="10dp"android:layout_marginBottom="3dp" /><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button4"android:layout_alignBottom="@+id/button4"android:layout_alignParentRight="true"android:background="#d89218"android:padding="10dp"android:text="+"android:textColor="#fff"android:textSize="10dp" /><Buttonandroid:id="@+id/button13"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/button3"android:layout_toLeftOf="@+id/button4"android:padding="10dp"android:text="."android:textColor="#fff"android:textSize="10dp"android:layout_marginRight="3dp"android:background="#d89218"  /><Buttonandroid:id="@+id/button12"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button13"android:layout_alignBottom="@+id/button13"android:layout_alignParentLeft="true"android:background="#666"android:padding="10dp"android:text="0"android:textColor="#fff"android:textSize="10dp"android:layout_marginRight="3dp" /><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/editText1"android:layout_alignParentTop="true"android:layout_alignRight="@+id/editText1"android:background="#666"android:text=" "android:textColor="#fff"android:textSize="15dp"android:textAppearance="?android:attr/textAppearanceLarge" /><EditTextandroid:id="@+id/editText1"android:layout_width="wrap_content"android:layout_height="40dp"android:layout_alignLeft="@+id/button17"android:layout_below="@+id/textView1"android:background="#666"android:ems="10"android:singleLine="true"android:textColor="#000"android:textSize="28dp" /></RelativeLayout>

相关文章:

Android入门

下载Android studio&#xff0c;创建第一个项目 模板可以选择empty views Activity 在这个界面可以修改&#xff0c;使用语言&#xff0c;项目名字&#xff0c;存储路径以及适用版本 完成后&#xff0c;得到一个最初始的Android 项目&#xff0c;红色标记的两个文件&#xf…...

二叉树深搜专题篇

目录 计算布尔二叉树的值 求根节点到叶节点数字之和 二叉树剪枝 验证二叉搜索树 二叉搜索树中第K小的元素 二叉树的所有路径 计算布尔二叉树的值 题目 思路 这道题其实是比较简单的&#xff0c;对二叉树来一次后序遍历即可&#xff0c;当遇到叶子结点直接返回叶子节点中…...

堆【数据结构C语言版】【 详解】

目录-笔记整理 一、思考二、堆概念与性质三、堆的构建、删除、添加1. 构建2. 删除3. 添加 四、复杂度分析4.1 时间复杂度4.2 空间复杂度 五、总结 一、思考 设计一种数据结构&#xff0c;来存放整数&#xff0c;要求三个接口&#xff1a; 1&#xff09;获取序列中的最值&#…...

初识React

在最新写需求的时候&#xff0c;我遇到了一个需求&#xff0c;这个需求改后端改的不算多&#xff0c;而且也比较简单&#xff0c;但是在改前端的时候&#xff0c;很复杂。因为我们这个项目用的是React做前端的&#xff0c;而我对于前端知识没有了解&#xff0c;所以理解很多代码…...

VUE 开发——AJAX学习(三)

一、async函数和await async和await关键字让我们可以用一种更简洁的方式写出基于Promise的异步行为&#xff0c;而无需刻意地链式调用Promise async写在函数声明的前面&#xff1b;在async函数内&#xff0c;使用await关键字&#xff0c;获取Promise对象“成功状态”结果值 &…...

C++杂项

作业&#xff1a; 将之前实现的顺序表、栈、队列都更改成模板类 顺序表 #include <iostream>using namespace std;template<typename T>class SeqList { private:T *ptr;int size; //总长度int len 0; //当前顺序表实际长度public://初始…...

Gelatinous Cube Sphere - Bonus Files 2 - Atavism

这是Gelatinous Cube & Sphere Pack的奖励文件包。 奖励文件&#xff1a; ⭐ 概念艺术 也可在Monster Bundle #2中使用。 下载&#xff1a;​​Unity资源商店链接资源下载链接...

锐捷—NAT地址映射+IPsec隧道

任务目标 在出口路由器R3上将R5私网地址1对1映射的公网地址与R1建立IPsec隧道&#xff0c;使得R4在访问R5的映射公网地址时&#xff0c;可以进行IPsec隧道的转发 要求&#xff1a; 1、R4和R5可通过NAT转换正常访问互联网地址&#xff08;R2的lo0&#xff09; 2、R5的私网地…...

index.html 调用 ajax

index.html <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><title>AJAX 请求示例</title><script>// 封装 Ajax 为公共函数&#xff1a;传入回调函数 success 和 failfunction myAjax (url, suc…...

uniapp学习(003-1 vue3学习 Part.1)

零基础入门uniapp Vue3组合式API版本到咸虾米壁纸项目实战&#xff0c;开发打包微信小程序、抖音小程序、H5、安卓APP客户端等 总时长 23:40:00 共116P 此文章包含第11p-第p14的内容 文章目录 vue3使用介绍插值表达式例子时间戳随机数输出函数的值 ref响应式数据变量v-bind 绑…...

计算机毕业设计 基于深度学习的短视频内容理解与推荐系统的设计与实现 Python+Django+Vue 前后端分离 附源码 讲解 文档

&#x1f34a;作者&#xff1a;计算机编程-吉哥 &#x1f34a;简介&#xff1a;专业从事JavaWeb程序开发&#xff0c;微信小程序开发&#xff0c;定制化项目、 源码、代码讲解、文档撰写、ppt制作。做自己喜欢的事&#xff0c;生活就是快乐的。 &#x1f34a;心愿&#xff1a;点…...

JavaScript网页设计案例深度解析:从理论到实践

前言 在现代前端开发中&#xff0c;JavaScript 是赋予网页生命的关键技术。静态的 HTML 和 CSS 虽然能创建美观的页面&#xff0c;但当我们需要增强用户交互和页面响应时&#xff0c;JavaScript 无疑成为最得力的工具。从程序员的角度来看&#xff0c;JavaScript 设计不仅仅是…...

spark-sql建表数据同步到hive

1、基础环境 组件版本备注hadoop3.4.0官方下载hive3.1.3自编译sparkspark-3.5.3-bin-hadoop3官方下载&#xff0c;需要内置hive的jar相关内容paimon0.9.0Maven官方下载jdk1.8.0_41maven3.9.6固定版本 2、停止服务、清理日志 先停止&#xff0c;清理数据 sudo kill -9 $(ps -ef…...

Django上下文处理器

1创建 &#xff08;如frontend目录下&#xff09;category_processors文件&#xff1a; def categories(request):from backend.models import Categorycategory_list Category.objects.all()return {category_list:category_list}这里&#xff0c;必须返回一个字典。 2&…...

旭升集团携手纷享销客,构建全方位客户关系管理平台

宁波旭升集团股份有限公司&#xff08;以下简称“旭升集团”&#xff09;自2003年成立&#xff0c;总部位于中国宁波&#xff0c;集团设有压铸、锻造、挤压、集成四大事业部&#xff0c;在亚洲、欧洲、美洲等地均设立研发中心及制造基地&#xff0c;产品主要覆盖新能源汽车的电…...

uniapp 知识点

自定义导航 在page.json navigationstyle":"custom"navigateTo传参 页面传参只能onLoad(option)里面拿 px和upx的关系 在750设计图中&#xff0c;1px1upx 路由 navigateBack返回上一页 重定向 其实就是把当前页面干掉了 公共组件和页面共同点 computed,watc…...

慢病中医药膳养生食疗管理微信小程序、基于微信小程序的慢病中医药膳养生食疗管理系统设计与实现、中医药膳养生食疗管理微信小程序的开发与应用(源码+文档+定制)

博主介绍&#xff1a; ✌我是阿龙&#xff0c;一名专注于Java技术领域的程序员&#xff0c;全网拥有10W粉丝。作为CSDN特邀作者、博客专家、新星计划导师&#xff0c;我在计算机毕业设计开发方面积累了丰富的经验。同时&#xff0c;我也是掘金、华为云、阿里云、InfoQ等平台…...

解决 Android WebView 无法加载 H5 页面常见问题的实用指南

目录 1. WebView 简介 2. 常见问题 3. 网络权限设置 4. 启用 JavaScript 5. DOM Storage 的重要性 6. 处理 HTTPS 问题 7. 设置 WebViewClient 8. 调试工具 9. 其他调试技巧 10. 结论 相关推荐 1. WebView 简介 Android WebView 是一种视图组件&#xff0c;使得 And…...

Ollama本地部署大模型及应用

文章目录 前言一、下载安装1.Mac2.Windows3.linux4.docker5.修改配置&#xff08;可选&#xff09;1.linux系统2.window 系统3.mac系统 二、Ollama使用1.命令2.模型下载3.自定义模型4.API 服务 三、Open WebUI 使用四、Dify使用 前言 Ollama 是一个专注于本地部署大型语言模型…...

读代码UNET

这个后面这个大小怎么算的&#xff0c;这参数怎么填&#xff0c;怎么来的&#xff1f; 这是怎么看怎么算的&#xff1f; 这些参数设置怎么设置&#xff1f;卷积多大&#xff0c;有什么讲究&#xff1f;...

第19节 Node.js Express 框架

Express 是一个为Node.js设计的web开发框架&#xff0c;它基于nodejs平台。 Express 简介 Express是一个简洁而灵活的node.js Web应用框架, 提供了一系列强大特性帮助你创建各种Web应用&#xff0c;和丰富的HTTP工具。 使用Express可以快速地搭建一个完整功能的网站。 Expre…...

使用VSCode开发Django指南

使用VSCode开发Django指南 一、概述 Django 是一个高级 Python 框架&#xff0c;专为快速、安全和可扩展的 Web 开发而设计。Django 包含对 URL 路由、页面模板和数据处理的丰富支持。 本文将创建一个简单的 Django 应用&#xff0c;其中包含三个使用通用基本模板的页面。在此…...

树莓派超全系列教程文档--(62)使用rpicam-app通过网络流式传输视频

使用rpicam-app通过网络流式传输视频 使用 rpicam-app 通过网络流式传输视频UDPTCPRTSPlibavGStreamerRTPlibcamerasrc GStreamer 元素 文章来源&#xff1a; http://raspberry.dns8844.cn/documentation 原文网址 使用 rpicam-app 通过网络流式传输视频 本节介绍来自 rpica…...

(转)什么是DockerCompose?它有什么作用?

一、什么是DockerCompose? DockerCompose可以基于Compose文件帮我们快速的部署分布式应用&#xff0c;而无需手动一个个创建和运行容器。 Compose文件是一个文本文件&#xff0c;通过指令定义集群中的每个容器如何运行。 DockerCompose就是把DockerFile转换成指令去运行。 …...

分布式增量爬虫实现方案

之前我们在讨论的是分布式爬虫如何实现增量爬取。增量爬虫的目标是只爬取新产生或发生变化的页面&#xff0c;避免重复抓取&#xff0c;以节省资源和时间。 在分布式环境下&#xff0c;增量爬虫的实现需要考虑多个爬虫节点之间的协调和去重。 另一种思路&#xff1a;将增量判…...

【C++特殊工具与技术】优化内存分配(一):C++中的内存分配

目录 一、C 内存的基本概念​ 1.1 内存的物理与逻辑结构​ 1.2 C 程序的内存区域划分​ 二、栈内存分配​ 2.1 栈内存的特点​ 2.2 栈内存分配示例​ 三、堆内存分配​ 3.1 new和delete操作符​ 4.2 内存泄漏与悬空指针问题​ 4.3 new和delete的重载​ 四、智能指针…...

作为测试我们应该关注redis哪些方面

1、功能测试 数据结构操作&#xff1a;验证字符串、列表、哈希、集合和有序的基本操作是否正确 持久化&#xff1a;测试aof和aof持久化机制&#xff0c;确保数据在开启后正确恢复。 事务&#xff1a;检查事务的原子性和回滚机制。 发布订阅&#xff1a;确保消息正确传递。 2、性…...

安卓基础(Java 和 Gradle 版本)

1. 设置项目的 JDK 版本 方法1&#xff1a;通过 Project Structure File → Project Structure... (或按 CtrlAltShiftS) 左侧选择 SDK Location 在 Gradle Settings 部分&#xff0c;设置 Gradle JDK 方法2&#xff1a;通过 Settings File → Settings... (或 CtrlAltS)…...

Vue ③-生命周期 || 脚手架

生命周期 思考&#xff1a;什么时候可以发送初始化渲染请求&#xff1f;&#xff08;越早越好&#xff09; 什么时候可以开始操作dom&#xff1f;&#xff08;至少dom得渲染出来&#xff09; Vue生命周期&#xff1a; 一个Vue实例从 创建 到 销毁 的整个过程。 生命周期四个…...

十九、【用户管理与权限 - 篇一】后端基础:用户列表与角色模型的初步构建

【用户管理与权限 - 篇一】后端基础:用户列表与角色模型的初步构建 前言准备工作第一部分:回顾 Django 内置的 `User` 模型第二部分:设计并创建 `Role` 和 `UserProfile` 模型第三部分:创建 Serializers第四部分:创建 ViewSets第五部分:注册 API 路由第六部分:后端初步测…...