安卓开发学习---kotlin版---笔记(二)

本文详细介绍了AndroidUI设计中的View和ViewGroup概念,以及LinearLayout、RelativeLayout、FrameLayout和MaterialButton的使用方法,同时展示了RecyclerView和自定义列表的实现。

UI学习

UI分类

安卓的UI分为两大类:一类叫做View视图,一类叫做ViewGroup容器

  • View视图:TextView,Button,ImageView都是常见的视图
  • ViewGroup容器:内部尅承载、放置、添加View视图的容器

布局方式

安卓布局主要有:线性布局、相对布局、帧布局、约束布局

LinearLayout线性布局

LinearLayout线性布局:横着或者竖着 按顺序排列
其属性主要有:

  • orientation:排列方向,主要有vertical垂直排列、horizontal水平排列
  • layout_width/height:宽度,主要有三种类型
  1. 填充父容器剩余空间:match_parent
  2. 根据子视图宽度自适应自己的宽高:wrap_content
  3. 自定义大小,比如50dp
  • background:背景颜色
  • gravity:重力,决定子控件相对该父容器的位置。主要有三种:
    center:居中显示
    horizontal_center:水平居中
    vertical_center:垂直居中
  • layout_gravity:决定该容器相对它的父容器的位置
<?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"
    android:background="#FF2299"
    android:gravity="center">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:backgroundTint="#FF00FF"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:backgroundTint="#FFFF00"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:backgroundTint="#00FF00"/>

</LinearLayout>

效果

RelativeLayout相对布局

在摆放子视图位置时,按照指定的参考系摆放子视图的位置,默认以屏幕左上角(0, 0)位置作为参考系摆放位置
主要有三大类:

  • 相对父元素
  • 相对兄弟元素
  • 相对兄弟元素对齐方式

在这里插入图片描述

在这里插入图片描述

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:insetTop="0dp"
        android:insetBottom="0dp"
        android:text="按钮1"/>

    <Button
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height=
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值