程序界面的功能是让用户观察和操作数据,能够响应用户的操作通知给程序。界面上的控件就是显示数据和响应用户操作的UI元素,控件就是数据和行为的载体。
TextView
主要用于界面上显示一段文本信息。
<TextView
android:id="@+id/textView"
android:layout_width="36dp"
android:layout_height="20dp"
android:text="你好!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
- android:id="@+id/textView",表示新增一个叫textView的id,并且设置当前这个控件的id叫做parent。
- android:layout_width:父布局允许view所占的宽度,而width是view的自身宽度。
- android:layout_height:父布局允许view所占的高度,而height是view的自身的高度。
- android:text:表示文本显示内容
-
layout_constraintTop_toTopOf:将所需视图的顶部与另一个视图的顶部对齐。
-
layout_constraintTop_toBottomOf:将所需视图的顶部与另一个视图的底部对齐。
-
layout_constraintBottom_toBottomOf:将所需视图的底部与另一个视图的底部对齐。
-
layout_constraintBottom_toTopOf:将所需视图的底部与另一个视图的顶部对齐。
-
layout_constraintLeft_toTopOf:将所需视图的左侧与另一个视图的顶部对齐。
-
layout_constraintLeft_toBottomOf:将所需视图的左侧与另一个视图的底部对齐。
-
。。。。
ConstraintLayout如果不是跟布局,布局里的子控件的约束不能设置为"parent",要设置@+id/父控件id(ConstraintLayout)