每日总结

1.今天深入学习了textview的相关属性

  • id:为TextView设置一个组件id,根据id,我们可以在Java代码中通过findViewById()的方法获取到该对象,然后进行相关属性的设置,又或者使用RelativeLayout时,参考组件用的也是id!
  • layout_width:组件的宽度,一般写:**wrap_content**或者**match_parent(fill_parent)**,前者是控件显示的内容多大,控件就多大,而后者会填满该控件所在的父容器;
  • layout_height:组件的高度,内容同上。
  • gravity:设置控件中内容的对齐方向,TextView中是文字,ImageView中是图片等等。
  • text:设置显示的文本内容,一般我们是把字符串写到string.xml文件中,然后通过@String/xxx取得对应的字符串内容的
  • textColor:设置字体颜色,同上,通过colors.xml资源来引用
  • textStyle:设置字体风格,三个可选值:**normal**(无效果),**bold**(加粗),**italic**(斜体)
  • textSize:字体大小,单位一般是用sp
  • background:控件的背景颜色,可以理解为填充整个控件的颜色
  • <TextView
    android:id="@+id/ShowTime"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="日期:"
    android:textColor="@color/black"
    android:layout_below="@id/butt_1"
    android:textSize="20sp" />
原文地址:https://www.cnblogs.com/chenghaixiang/p/14908135.html