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

后进先出(LIFO)详解

LIFO 是 Last In, First Out 的缩写&#xff0c;中文译为后进先出。这是一种数据结构的工作原则&#xff0c;类似于一摞盘子或一叠书本&#xff1a; 最后放进去的元素最先出来 -想象往筒状容器里放盘子&#xff1a; &#xff08;1&#xff09;你放进的最后一个盘子&#xff08…...

Ubuntu系统下交叉编译openssl

一、参考资料 OpenSSL&&libcurl库的交叉编译 - hesetone - 博客园 二、准备工作 1. 编译环境 宿主机&#xff1a;Ubuntu 20.04.6 LTSHost&#xff1a;ARM32位交叉编译器&#xff1a;arm-linux-gnueabihf-gcc-11.1.0 2. 设置交叉编译工具链 在交叉编译之前&#x…...

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

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

镜像里切换为普通用户

如果你登录远程虚拟机默认就是 root 用户&#xff0c;但你不希望用 root 权限运行 ns-3&#xff08;这是对的&#xff0c;ns3 工具会拒绝 root&#xff09;&#xff0c;你可以按以下方法创建一个 非 root 用户账号 并切换到它运行 ns-3。 一次性解决方案&#xff1a;创建非 roo…...

Spring AI 入门:Java 开发者的生成式 AI 实践之路

一、Spring AI 简介 在人工智能技术快速迭代的今天&#xff0c;Spring AI 作为 Spring 生态系统的新生力量&#xff0c;正在成为 Java 开发者拥抱生成式 AI 的最佳选择。该框架通过模块化设计实现了与主流 AI 服务&#xff08;如 OpenAI、Anthropic&#xff09;的无缝对接&…...

【学习笔记】深入理解Java虚拟机学习笔记——第4章 虚拟机性能监控,故障处理工具

第2章 虚拟机性能监控&#xff0c;故障处理工具 4.1 概述 略 4.2 基础故障处理工具 4.2.1 jps:虚拟机进程状况工具 命令&#xff1a;jps [options] [hostid] 功能&#xff1a;本地虚拟机进程显示进程ID&#xff08;与ps相同&#xff09;&#xff0c;可同时显示主类&#x…...

使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台

🎯 使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台 📌 项目背景 随着大语言模型(LLM)的广泛应用,开发者常面临多个挑战: 各大模型(OpenAI、Claude、Gemini、Ollama)接口风格不统一;缺乏一个统一平台进行模型调用与测试;本地模型 Ollama 的集成与前…...

深度学习习题2

1.如果增加神经网络的宽度&#xff0c;精确度会增加到一个特定阈值后&#xff0c;便开始降低。造成这一现象的可能原因是什么&#xff1f; A、即使增加卷积核的数量&#xff0c;只有少部分的核会被用作预测 B、当卷积核数量增加时&#xff0c;神经网络的预测能力会降低 C、当卷…...

2025季度云服务器排行榜

在全球云服务器市场&#xff0c;各厂商的排名和地位并非一成不变&#xff0c;而是由其独特的优势、战略布局和市场适应性共同决定的。以下是根据2025年市场趋势&#xff0c;对主要云服务器厂商在排行榜中占据重要位置的原因和优势进行深度分析&#xff1a; 一、全球“三巨头”…...

排序算法总结(C++)

目录 一、稳定性二、排序算法选择、冒泡、插入排序归并排序随机快速排序堆排序基数排序计数排序 三、总结 一、稳定性 排序算法的稳定性是指&#xff1a;同样大小的样本 **&#xff08;同样大小的数据&#xff09;**在排序之后不会改变原始的相对次序。 稳定性对基础类型对象…...