当前位置: 首页 > 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;...

AI-调查研究-01-正念冥想有用吗?对健康的影响及科学指南

点一下关注吧&#xff01;&#xff01;&#xff01;非常感谢&#xff01;&#xff01;持续更新&#xff01;&#xff01;&#xff01; &#x1f680; AI篇持续更新中&#xff01;&#xff08;长期更新&#xff09; 目前2025年06月05日更新到&#xff1a; AI炼丹日志-28 - Aud…...

多模态2025:技术路线“神仙打架”,视频生成冲上云霄

文&#xff5c;魏琳华 编&#xff5c;王一粟 一场大会&#xff0c;聚集了中国多模态大模型的“半壁江山”。 智源大会2025为期两天的论坛中&#xff0c;汇集了学界、创业公司和大厂等三方的热门选手&#xff0c;关于多模态的集中讨论达到了前所未有的热度。其中&#xff0c;…...

Spark 之 入门讲解详细版(1)

1、简介 1.1 Spark简介 Spark是加州大学伯克利分校AMP实验室&#xff08;Algorithms, Machines, and People Lab&#xff09;开发通用内存并行计算框架。Spark在2013年6月进入Apache成为孵化项目&#xff0c;8个月后成为Apache顶级项目&#xff0c;速度之快足见过人之处&…...

Unity3D中Gfx.WaitForPresent优化方案

前言 在Unity中&#xff0c;Gfx.WaitForPresent占用CPU过高通常表示主线程在等待GPU完成渲染&#xff08;即CPU被阻塞&#xff09;&#xff0c;这表明存在GPU瓶颈或垂直同步/帧率设置问题。以下是系统的优化方案&#xff1a; 对惹&#xff0c;这里有一个游戏开发交流小组&…...

【Go】3、Go语言进阶与依赖管理

前言 本系列文章参考自稀土掘金上的 【字节内部课】公开课&#xff0c;做自我学习总结整理。 Go语言并发编程 Go语言原生支持并发编程&#xff0c;它的核心机制是 Goroutine 协程、Channel 通道&#xff0c;并基于CSP&#xff08;Communicating Sequential Processes&#xff0…...

SpringBoot+uniapp 的 Champion 俱乐部微信小程序设计与实现,论文初版实现

摘要 本论文旨在设计并实现基于 SpringBoot 和 uniapp 的 Champion 俱乐部微信小程序&#xff0c;以满足俱乐部线上活动推广、会员管理、社交互动等需求。通过 SpringBoot 搭建后端服务&#xff0c;提供稳定高效的数据处理与业务逻辑支持&#xff1b;利用 uniapp 实现跨平台前…...

新能源汽车智慧充电桩管理方案:新能源充电桩散热问题及消防安全监管方案

随着新能源汽车的快速普及&#xff0c;充电桩作为核心配套设施&#xff0c;其安全性与可靠性备受关注。然而&#xff0c;在高温、高负荷运行环境下&#xff0c;充电桩的散热问题与消防安全隐患日益凸显&#xff0c;成为制约行业发展的关键瓶颈。 如何通过智慧化管理手段优化散…...

linux 下常用变更-8

1、删除普通用户 查询用户初始UID和GIDls -l /home/ ###家目录中查看UID cat /etc/group ###此文件查看GID删除用户1.编辑文件 /etc/passwd 找到对应的行&#xff0c;YW343:x:0:0::/home/YW343:/bin/bash 2.将标红的位置修改为用户对应初始UID和GID&#xff1a; YW3…...

JVM暂停(Stop-The-World,STW)的原因分类及对应排查方案

JVM暂停(Stop-The-World,STW)的完整原因分类及对应排查方案,结合JVM运行机制和常见故障场景整理而成: 一、GC相关暂停​​ 1. ​​安全点(Safepoint)阻塞​​ ​​现象​​:JVM暂停但无GC日志,日志显示No GCs detected。​​原因​​:JVM等待所有线程进入安全点(如…...

服务器--宝塔命令

一、宝塔面板安装命令 ⚠️ 必须使用 root 用户 或 sudo 权限执行&#xff01; sudo su - 1. CentOS 系统&#xff1a; yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh2. Ubuntu / Debian 系统…...