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

uni-app学习笔记二十二---使用vite.config.js全局导入常用依赖

在前面的练习中&#xff0c;每个页面需要使用ref&#xff0c;onShow等生命周期钩子函数时都需要像下面这样导入 import {onMounted, ref} from "vue" 如果不想每个页面都导入&#xff0c;需要使用node.js命令npm安装unplugin-auto-import npm install unplugin-au…...

ardupilot 开发环境eclipse 中import 缺少C++

目录 文章目录 目录摘要1.修复过程摘要 本节主要解决ardupilot 开发环境eclipse 中import 缺少C++,无法导入ardupilot代码,会引起查看不方便的问题。如下图所示 1.修复过程 0.安装ubuntu 软件中自带的eclipse 1.打开eclipse—Help—install new software 2.在 Work with中…...

Android第十三次面试总结(四大 组件基础)

Activity生命周期和四大启动模式详解 一、Activity 生命周期 Activity 的生命周期由一系列回调方法组成&#xff0c;用于管理其创建、可见性、焦点和销毁过程。以下是核心方法及其调用时机&#xff1a; ​onCreate()​​ ​调用时机​&#xff1a;Activity 首次创建时调用。​…...

Docker 本地安装 mysql 数据库

Docker: Accelerated Container Application Development 下载对应操作系统版本的 docker &#xff1b;并安装。 基础操作不再赘述。 打开 macOS 终端&#xff0c;开始 docker 安装mysql之旅 第一步 docker search mysql 》〉docker search mysql NAME DE…...

写一个shell脚本,把局域网内,把能ping通的IP和不能ping通的IP分类,并保存到两个文本文件里

写一个shell脚本&#xff0c;把局域网内&#xff0c;把能ping通的IP和不能ping通的IP分类&#xff0c;并保存到两个文本文件里 脚本1 #!/bin/bash #定义变量 ip10.1.1 #循环去ping主机的IP for ((i1;i<10;i)) doping -c1 $ip.$i &>/dev/null[ $? -eq 0 ] &&am…...

STL 2迭代器

文章目录 1.迭代器2.输入迭代器3.输出迭代器1.插入迭代器 4.前向迭代器5.双向迭代器6.随机访问迭代器7.不同容器返回的迭代器类型1.输入 / 输出迭代器2.前向迭代器3.双向迭代器4.随机访问迭代器5.特殊迭代器适配器6.为什么 unordered_set 只提供前向迭代器&#xff1f; 1.迭代器…...

DriveGPT4: Interpretable End-to-end Autonomous Driving via Large Language Model

一、研究背景与创新点 (一)现有方法的局限性 当前智驾系统面临两大核心挑战:一是长尾问题,即系统在遇到新场景时可能失效,例如突发交通状况或非常规道路环境;二是可解释性问题,传统方法无法解释智驾系统的决策过程,用户难以理解车辆行为的依据。传统语言模型(如 BERT…...

Flask和Django,你怎么选?

Flask 和 Django 是 Python 两大最流行的 Web 框架&#xff0c;但它们的设计哲学、目标和适用场景有显著区别。以下是详细的对比&#xff1a; 核心区别&#xff1a;哲学与定位 Django: 定位: "全栈式" Web 框架。奉行"开箱即用"的理念。 哲学: "包含…...

项目研究:使用 LangGraph 构建智能客服代理

概述 本教程展示了如何使用 LangGraph 构建一个智能客服代理。LangGraph 是一个强大的工具&#xff0c;可用于构建复杂的语言模型工作流。该代理可以自动分类用户问题、分析情绪&#xff0c;并根据需要生成回应或升级处理。 背景动机 在当今节奏飞快的商业环境中&#xff0c…...

React 样式方案与状态方案初探

React 本身只提供了基础 UI 层开发范式&#xff0c;其他特性的支持需要借助相关社区方案实现。本文将介绍 React 应用体系中样式方案与状态方案的主流选择&#xff0c;帮助开发者根据项目需求做出合适的选择。 1. React 样式方案 1.1. 内联样式 (Inline Styles) 通过 style …...