在Android Studio中创建XML页面布局代码—大学Android实验

1.打开 Android Studio 新建一个名为XML的 Empty Activity 项目

6e08fe53279344fcafa5f2c5f72cb3d0.png

79fb5705ac024f42a0f3deaa624fbaf6.png

 2.在目录中新建一个activity_main.xml文件

ccb29d3a6f9d4002bddec48a8069f2db.png

 3.在activity_main.xml中编写XML页面布局代码

(1)上下左右中心按钮布局

①源代码

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

   xmlns:tools="http://schemas.android.com/tools"

   android:layout_width="match_parent"

   android:layout_height="match_parent">

   <Button

       android:id="@+id/btnUp"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:layout_above="@+id/btnCenter"

       android:layout_centerInParent="true"

       android:text="上"

       tools:ignore="HardcodedText" />

   <Button

       android:id="@+id/btnLeft"

       android:text="左"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:layout_toLeftOf="@+id/btnCenter"

       android:layout_below="@+id/btnUp"

       tools:ignore="HardcodedText,RtlHardcoded" />

   <Button

       android:id="@+id/btnCenter"

       android:text="中心"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:layout_centerInParent="true"

       tools:ignore="HardcodedText" />

   <Button

       android:id="@+id/btnRight"

       android:text="右"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:layout_toRightOf="@+id/btnCenter"

       android:layout_below="@+id/btnUp"

       tools:ignore="HardcodedText,RtlHardcoded" />

   <Button

       android:id="@+id/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值