Android开发-概述,线性布局,相对布局

概述

1.Android是Google开发的操作系统。

  1. Android开发是移动应用开发的表现形式之一。

项目精简流程

示意图

开发工具

Android Studio

  • 下载安装JDK
  • 为什么使用Android Studio?
    Android Studio 是Google自己退出的Android集成开发工具,并且停止对Eclipse的支持。

项目结构

!!

布局管理器

  • 线性布局(LinearLayout)
  • 相对布局(RelativeLayout)

LinearLayout

常用属性
android:id 布局标识
android:layout_width 宽度
android:layout_height 高度
android:background 背景,颜色图片控件等
android:layout_margin 外边距
android:layout_padding 内边距
android:orientation 布局方向
android:gravity 布局开始位置
android:layout_weight 比重

效果图


线性布局效果图

示例代码

<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"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:orientation="vertical"
        android:background="#000000"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="50dp"
        android:paddingBottom="10dp"
        android:layout_marginLeft="15dp">

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ff0033"
            />
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:orientation="horizontal"
        android:background="#0066FF"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:gravity="center"
        >
        
        <View
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#4CAF50"/>
        <View
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:background="#ff0033"/>
        <View
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:background="#FFC107"/>
        
    </LinearLayout>

</LinearLayout>

RelativeLayout

常用属性
android:layout_toLeftOf 在谁的左边
android:layout_toRightOf 在谁的右边
android:layout_alignBottom 底部对齐
android:layout_alignParentBottom 父控件底部对齐
android:layout_below 在谁的下面

效果图
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <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="#F44336"
        android:layout_below="@id/view_1"/>
    <!--android:layout_toRightOf="@id/view_1"-->

    <LinearLayout
        android:id="@+id/view_3"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="#0066ff"
        android:layout_below="@id/view_2"
        android:orientation="horizontal"
        android:padding="15dp"
        >

        <View
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:background="#FF0033"
            />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000000"
            android:padding="15dp"
            >

            <View
                android:id="@+id/view_4"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:background="#9C27B0"
                />
            <View
                android:id="@+id/view_5"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:background="#9C27B0"
                android:layout_toRightOf="@id/view_4"
                android:layout_marginLeft="10dp"
                />
        </RelativeLayout>
    </LinearLayout>
</RelativeLayout>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容