创建splash布局

<?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">

    <TextView
        android:id="@+id/welcome_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/welcome"
        android:layout_centerInParent="true"
        android:textSize="28sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/version"
        android:layout_centerInParent="true"
        android:layout_below="@+id/welcome_tv"
        android:textSize="16sp"
        />

</RelativeLayout>

代码解释: 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout     相对布局
    xmlns:android="http://schemas.android.com/apk/res/android"   xmlns开头的都是命名空间
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"   定义容器的宽度,容器宽度一般取值match_parent
    android:layout_height="match_parent"  定义容器的高度,match_parent表示按照屏幕大小
    tools:context=".MainActivity">

    <TextView       文本控件
        android:id="@+id/welcome_tv"   给控件取名字,名字id值是唯一的
        android:layout_width="wrap_content"   定义控件的宽度,wrap_content表示按内容大小
        android:layout_height="wrap_content"  定义控件的高度
        android:text="欢迎使用智慧工厂应用"   定义控件的文本内容
        android:layout_centerInParent="true"  定义控件的位置:父容器居中
        android:textSize="28sp" />   定义字体大小

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="版本1.0"
        android:layout_centerInParent="true"
        android:layout_below="@+id/welcome_tv"   定义控件的位置,相对于某个控件的下面
        android:textSize="16sp"   定义字体大小,单位为sp
        />

</RelativeLayout>

设置主界面运行:

上面的字符串也可以在values中的strings.xml中去定义,这个好处是方便后期维护修改

在布局中引用字符串资源:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值