安卓开发
Base on : https://www.bilibili.com/video/BV1Rt411e76H?p=7
1、Android开发概述
2、UI组件
2.1 布局管理器
线性布局(LinearLayout)
常用属性
| android:id | id |
|---|---|
| android:layout_width | 宽度 |
| android:layout_height | 高度 |
| android:backgroud | 背景 |
| android:layout_margin | 内边距 |
| android:layout_padding | 外边距 |
| android:orientation | 方向 |
<?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:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/ll_1"
android:layout_width="200dp"
android:layout_height="200dp"
android:orientation="vertical"
android:background="@color/black"
android:padding="20dp">
<!--View是所有控件的父控件-->
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0033" />
</LinearLayout>
<!-- match_parent 匹配父控件-->
<!--
因为是匹配父控件,因此上面占用了200dp之后的都是这个的
LinearLayout是默认水平布局的
-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="horizontal"
android:background="#0066FF"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
>
<View
android:layout_width="0dp"
android:layout_height="200dp"
android:background="#000000"
android:layout_weight="1"/>
<View
android:layout_width="0dp"
android:layout_height="200dp"
android:background="#FF0033"
android:layout_weight="1"/>
<View
android:layout_width="0dp"
android:layout_height="200dp"
android:background="#55AA99"
android:layout_weight="1"/>
</LinearLayout>
<!-- android:gravity 内部空间布局-->
<!-- android:layout_weight 权重 -->
</LinearLayout>


相对布局(RelativeLayout)
最常用的属性
| android:layout_toLeftOf | 现对布局:在… 左边 |
|---|---|
| android:layout_toRightOf | 现对布局:在… 右边 |
| android:layout_alignBottom | 和…底部对齐 |
| android:layout_AlignParentBottom | 和父控件底部对齐 |
| android:layout_below | 在…下面 |
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_height="match_parent"
tools:context=".MainActivity">
<View
android:id="@+id/view_1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#000000"
/>
<View
android:id="@+id/view_2"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#FF0033"
android:layout_below="@id/view_1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@id/view_2"
android:background="#0066FF"
android:orientation="horizontal"
android:padding=
这篇博客介绍了安卓开发的基础,重点关注UI组件的使用。涵盖了线性布局和相对布局的属性,TextView的文字处理和特殊效果,Button的定制及事件处理,以及EditText的常见属性和登录界面制作,还涉及RadioButton的基本属性和事件监听。
最低0.47元/天 解锁文章
3132

被折叠的 条评论
为什么被折叠?



