<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/textColor"
android:textSize="26sp"
android:text="Hello World!"
android:gravity="center"
/>
</LinearLayout>
定义的唯一标识符
android:id="@+id/textView3
指定控件的宽度和高度,在android中所有的的控件都有这两个属性。选值有三种:match_parent,wrap_content,fill_parent。match_parent和fill_parent意义相同。
- match_parent:让当前控件的大小和父布局的大小一样。由父布局来决定当前控件的大小
- wrap_content:让当前控件的大小能够刚好包含住里面的内容,也就是由控件内容决定当前控件的大小。
android:layout_width="match_parent
android:layout_height="wrap_content
在TextView中文字默认居左上角对齐的,有时文字内容不够长,并没有覆盖整个屏幕宽度通过修改android:gravity来调整对齐方式.可选值有top,bottom,left,right,center。可以用 | 来同时指定多个值。center效果等同于center_vertical | center_horizontal,表示文字在垂直和水平方向都居中对齐
android:gravity="center"
文字大小和颜色,通过android:textSize属性指定文字大小,通过android:textColor属性指定文字颜色,在Android中字体大小使用sp作为单位。
android:textColor="@color/textColor"
android:textSize="26sp"

本文详细介绍了Android应用开发中的基本布局设置,包括LinearLayout的使用方法、TextView的属性设置等内容。重点讲解了如何通过不同的属性如match_parent、wrap_content以及fill_parent来控制控件的尺寸,同时还涉及了文字对齐方式及颜色大小的设定。
596

被折叠的 条评论
为什么被折叠?



