Android-第一节基础知识及LinearLayout(线性布局)

<LinearLayout

android:id=“@+id/linearLayout”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:orientation=“horizontal”

app:layout_constraintEnd_toEndOf=“parent”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toTopOf=“parent”>

<Button

android:id=“@+id/button1”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_weight=“1”

android:text=“button1”>

<Button

android:id=“@+id/button2”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_weight=“1”

android:visibility=“gone” //gone 表示控件不可见,也不会占任何的位置,也不会有任何响应。

android:text=“button2”>

<Button

android:id=“@+id/button3”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_weight=“1”

android:text=“button3”>

效果如图:在这里插入图片描述

1.2控件的外边距


学习过HTML的都会知道CSS里的盒模式有个外边距和内边距。

外边距可以设置视图距离父视图上下左右的距离。

内边距可以设置视图内部内容距离自己边框上下左右的距离。

Android 的控件布局其实也用的是这个盒模式。

如果距离父视图上下左右的外边距相同,可以这么设置:

android:layout_margin=“10dp”

我们也可以单独的设置某个外边距:

android:layout_marginTop=“10dp”

android:layout_marginBottom=“10dp”

android:layout_marginLeft=“10dp”

android:layout_marginRight=“10dp”

1.3控件的内边距


统一设置上下左右内边距:

android:padding=“5dp”

各自设置内边距:

android:paddingTop=“5dp”

android:paddingBottom=“5dp”

android:paddingLeft=“5dp”

android:paddingRight=“5dp”

2.线性布局(Linear Layout)

====================================================================================

LinearLayout 核心属性:

​ (1) android:orientation:两个属性值:“vertical” 垂直 “horizontal”水平

​ (2) android:layout_weight 将父控件的剩余空间按照设置的权重比例再分配

2.1示例:


在这里插入图片描述

<LinearLayout

android:id=“@+id/linearLayout”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:orientation=“horizontal”

app:layout_constraintEnd_toEndOf=“parent”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toTopOf=“parent”>

<Button

android:id=“@+id/button1”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“button1”>

<Button

android:id=“@+id/button2”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“button2”>

<Button

android:id=“@+id/button3”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“button3”>

2.2微信界面实战


在这里插入图片描述

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:app=“http://schemas.android.com/apk/res-auto”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:orientation=“vertical”

android:layout_height=“match_parent”

tools:context=“.MainActivity”>

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“×”

android:textSize=“50dp”

android:layout_marginLeft=“5dp”/>

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“20dp”

android:layout_marginTop=“5dp”

android:text=“微信号/QQ/邮箱登录”

android:textColor=“@color/black”

android:textSize=“30dp”/>

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_marginTop=“30dp”>

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_weight=“1”

android:layout_marginTop=“6dp”

android:orientation=“horizontal”>

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“25dp”

android:text=“账号”

android:textColor=“@color/black”

android:textSize=“25dp” />

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_weight=“0”>

<EditText

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:text="请填写微信号/QQ号/邮箱 "/>

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“45dp”

android:layout_marginTop=“10dp”

android:orientation=“horizontal”>

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_weight=“1”>

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“25dp”

android:text=“密码”

android:textColor=“@color/black”

android:textSize=“25dp” />

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_weight=“0”>

<EditText

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="请填写密码 "/>

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(资料价值较高,非无偿)

总结:

各行各样都会淘汰一些能力差的,不仅仅是IT这个行业,所以,不要被程序猿是吃青春饭等等这类话题所吓倒,也不要觉得,找到一份工作,就享受安逸的生活,你在安逸的同时,别人正在奋力的向前跑,这样与别人的差距也就会越来越遥远,加油,希望,我们每一个人,成为更好的自己。

  • BAT大厂面试题、独家面试工具包,

  • 资料包括 数据结构、Kotlin、计算机网络、Framework源码、数据结构与算法、小程序、NDK、Flutter

《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门即可获取!

战项目、讲解视频,并且会持续更新!**

如果你觉得这些内容对你有帮助,可以扫码获取!!(资料价值较高,非无偿)

总结:

各行各样都会淘汰一些能力差的,不仅仅是IT这个行业,所以,不要被程序猿是吃青春饭等等这类话题所吓倒,也不要觉得,找到一份工作,就享受安逸的生活,你在安逸的同时,别人正在奋力的向前跑,这样与别人的差距也就会越来越遥远,加油,希望,我们每一个人,成为更好的自己。

  • BAT大厂面试题、独家面试工具包,

  • 资料包括 数据结构、Kotlin、计算机网络、Framework源码、数据结构与算法、小程序、NDK、Flutter
    [外链图片转存中…(img-W1yah4oM-1711559321207)]

《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门即可获取!
  • 17
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 创建一个新的Android Studio项目,并在activity_main.xml中打开设计视图。 2. 将LinearLayout拖放到屏幕上,并在属性检查器中设置以下属性: orientation:vertical(垂直方向) gravity:center(居中对齐) padding:16dp(内边距) 3. 在LinearLayout中添加一个TextView,用于显示应用程序名称或欢迎消息。 4. 接下来,使用两个EditText小部件添加一个LinearLayout,用于输入用户名和密码。为了使它们看起来更漂亮,可以使用drawable文件夹中的几个图标。 5. 紧接着,添加一个Button,用于提交登录或注册信息。可以使用selector文件夹中的几个不同状态的按钮,如pressed和focused。 6. 最后,添加一个TextView链接到注册页面,并在LinearLayout中设置gravity属性以居中对齐。 完成后,您的用户登录注册界面应该如此: ``` <LinearLayout android:orientation="vertical" android:gravity="center" android:padding="16dp" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:text="MyApp" android:textSize="24sp" android:textStyle="bold" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <LinearLayout android:orientation="vertical" android:layout_marginTop="24dp" android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:hint="Username" android:drawableLeft="@drawable/ic_person_outline_black_24dp" android:layout_width="match_parent" android:layout_height="wrap_content"/> <EditText android:hint="Password" android:drawableLeft="@drawable/ic_lock_outline_black_24dp" android:inputType="textPassword" android:layout_marginTop="16dp" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout> <Button android:text="Login" android:textColor="#fff" android:background="@drawable/btn_bg" android:layout_marginTop="24dp" android:layout_width="match_parent" android:layout_height="wrap_content"/> <TextView android:text="Don't have an account? Register" android:textColor="@color/colorPrimaryDark" android:layout_marginTop="24dp" android:layout_gravity="center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值