Android设计与开发——Layout课堂笔记

本文是关于Android设计与开发的课堂笔记,详细介绍了如何在Android Studio中创建新页面,包括从建立空活动开始,设置布局方向,调整按钮位置,利用layout_weight实现页面平均分配,以及如何合并LinearLayout和处理AndroidManifest.xml文件确保正确显示界面。

在Android studio建立新页面
Res->layout->右键new->Activity->Empty Activity

1.布局三个按钮

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:layout_width="150dp"
        android:layout_height="88dp"
        android:text="按钮1"></Button>
    <Button
        android:layout_width="150dp"
        android:layout_height="88dp"
        android:text="按钮2"></Button>
    <Button
        android:layout_width="150dp"
        android:layout_height="88dp"
        android:text="按钮3"></Button>
</LinearLayout>

此时默认水平布局

2.改成垂直布局

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"      //靠边垂直(之后第4步时选择了horizontal水平布局)
android:gravity="center"            //页面正中

3.在Button里改成正中(仅作对比实验,完成后回到2)

<Button
    android:layout_width="150dp"
    android:layout_height="88dp"
   android:text="按钮1"
   android:layout_gravity="center"></Button>

4.在linearlayout里放两个linearlayout

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#ff00">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1256"
            android:textSize="36sp"></TextView>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#00FFA6">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ABCD"
            android:textSize="36sp"></TextView>
    </LinearLayout>
</LinearLayout>

在这里插入图片描述

5.页面平均分(layout_weight=“1”)

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="#ff00"
    android:layout_weight="1">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="1256"
        android:textSize="36sp"></TextView>
</LinearLayout>
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="#00FFA6"
    android:layout_weight="1">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ABCD"
        android:textSize="36sp"></TextView>
</LinearLayout>

在这里插入图片描述

6.合并Linearlayout

先复制整个外层LinearLayout,然后到最底层粘贴,再用新的一个LinearLayout包住这两个LinearLayout

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">




<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:orientation="horizontal">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#ff00"
        android:layout_weight="1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1256"
            android:textSize="36sp"></TextView>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#00FFA6"
        android:layout_weight="1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ABCD"
            android:textSize="36sp"></TextView>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#BBFF00"
        android:layout_weight="1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RRDSD"
            android:textSize="36sp"></TextView>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#FF7700"
        android:layout_weight="1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="GGHH"
            android:textSize="36sp"></TextView>
    </LinearLayout>
</LinearLayout>




<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:orientation="horizontal">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#ff00"
        android:layout_weight="1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1256"
            android:textSize="36sp"></TextView>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#00FFA6"
        android:layout_weight="1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ABCD"
            android:textSize="36sp"></TextView>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#BBFF00"
        android:layout_weight="1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RRDSD"
            android:textSize="36sp"></TextView>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#FF7700"
        android:layout_weight="1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="GGHH"
            android:textSize="36sp"></TextView>
    </LinearLayout>
</LinearLayout>

</LinearLayout>

在这里插入图片描述

7.更改app->manifests->AndroidManifest.xml文件

让intent-filter在Linear_Layout里,就不会还是出现上次运行的界面了

<activity android:name=".Linear_Layout">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity android:name=".MainActivity">

</activity>

8.运行
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值