Android开发-Android APP实操-1.项目创建及启动页面UI编码

一、项目创建及模拟器安装

1.选择新建一个project

2. 选择空模板

3.完成新project的设置

 下载完成后点击Finish

4.下载安卓模拟器

 选择Pixel7

点击下载R

 为虚拟机命名,选择竖屏,点击Finish.

5.点击启动,测试运行

 运行成功!

 

二、启动页面UI编码

 1.打开MainActivity.java文件,Ctrl+左键进入activity_main.xml

 

 

2.在activity_main.xml中点击右键,进入xml编写UI页面模式

 

 

3.修改activity_main.xml的代码,识别手写xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".MainActivity">



</RelativeLayout>

 

4.AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyApplication1"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

 

activity_main:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="@mipmap/ic_launcher"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="44dp"
        android:paddingRight="44dp"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="90dp">

        <Button
            android:layout_alignParentLeft="true"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:text="@string/login"
            android:textSize="20sp"
            android:textColor="#ffffff"
            android:background="@drawable/shape_login_btn"/>


        <Button
            android:layout_alignParentRight="true"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:text="@string/register"
            android:textSize="20sp"
            android:textColor="#ffffff"
            android:background="@drawable/shape_register_btn"/>
    </RelativeLayout>



</RelativeLayout>

 

strings.xml:

<resources>
    <string name="app_name">MyApplication1</string>
    <string name="login">登录</string>
    <string name="register">注册</string>
</resources>

shape_login_btn.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="9dp" />
    <solid android:color="#c75fe768" />
</shape>

shape_register_btn.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="9dp" />
    <solid android:color="#c75fe768" />
</shape>

 

 

5.启动运行

 

posted @ 2024-03-27 16:11  临易  阅读(7)  评论(0编辑  收藏  举报