寒假学习进度二——安卓的基本布局

今天主要还是观看了哔哩哔哩上的安卓教学视频,这次感觉学有点水,感觉讲的有点过于基础和知识点重复,于是自己就敲了有关安卓布局管理器的代码。

今天学到的几种安卓布局管理器:

相对布局管理器:在一个参考点的四周(上,下,左,右)布局的管理器,即位置都是相对的。

线性布局管理器:分为水平和垂直两种,垂直较为常用,垂直布局相和横格纸类似。

帧布局管理器(这个不常用):在帧布局管理中,每加入一个组件,都将创建一个空白的区域,通常称为帧,这些帧都会根据gravity属性执行自动对齐。默认情况下,帧布局从屏幕的左上角(0,0)坐标点开始布局,多个组件层叠排序,后面的组件覆盖前面的组件。

表格布局管理器和网格布局管理器较为类似,两者都呈格子布局。不过网格布局较为灵活。

练习案例:

相对布局:主要按照相对位置放置了两个按钮和一个文本框

 线性布局:主要写了个微信登录界面

 activity_main.xml源码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <!--第一行-->
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="20dp"
        android:hint="@string/text1"
        android:drawableLeft="@mipmap/zhanghao"
        android:inputType="text"
        />
    <!--第二行-->
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="20dp"
        android:hint="@string/text2"
        android:drawableLeft="@mipmap/mima"
        android:inputType="textPassword"
        android:autofillHints="password"
        />
    <!--第三行-->
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/text3"
        android:textColor="#FFFFFF"
        android:background="#FF009688"/>
    <!--第四行-->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/text4"
        android:gravity="center_horizontal"
        android:paddingTop="20dp"/>
</LinearLayout>
View Code

帧布局管理器案例:

 网格布局管理器案例:

原文地址:https://www.cnblogs.com/weixiao1717/p/12254306.html