Android的xml布局文件代码讲解(TextView控件)

本文详细解析了Android中的XML布局文件,以activity_main.xml为例,讲解了如何使用RelativeLayout并配置TextView控件。重点阐述了android:layout_width、android:layout_height属性以及如何通过android:layout_centerHorizontal和android:layout_centerVertical实现控件的居中显示,并介绍了如何设置显示文本。

Android的xml布局文件代码讲解(TextView控件)

以一个activity_main.xml为例

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

指定布局的高度


    tools:context=".MainActivity" >

指定布局所关联的Activity(可以不写)


    <TextView

指定文本显示控件开始标签


        android:id="@+id/main_hello"

指定控件的id(方便java编程时调用)


        android:layout_width="wrap_content"

指定控件的宽度


        android:layout_height="wrap_content"

指定控件的高度


        android:layout_centerHorizontal="true"

指定控件相对于父布局横向居中显示


        android:layout_centerVertical="true"

指定控件相对于父布局垂直居中显示


        android:text="好吗?"

指定文本控件显示的文本
        />
    


</RelativeLayout>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值