• 每日总结


    今天学习的是Android的TextView(文本框)

    布局代码:

    <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"
        android:gravity="center"
        android:background="#8fffad">
    
        <TextView
            android:id="@+id/txtOne"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:gravity="center"
            android:text="TextView(显示框)"
            android:textColor="#EA5246"
            android:textStyle="bold|italic"
            android:background="#000000"
            android:textSize="18sp" />
    
    </RelativeLayout>
     

    上面的TextView中有下述几个属性:

    • id:为TextView设置一个组件id,根据id,我们可以在Java代码中通过findViewById()的方法获取到该对象,然后进行相关属性的设置,又或者使用RelativeLayout时,参考组件用的也是id!
    • layout_width:组件的宽度,一般写:**wrap_content**或者**match_parent(fill_parent)**,前者是控件显示的内容多大,控件就多大,而后者会填满该控件所在的父容器;当然也可以设置成特定的大小,比如我这里为了显示效果,设置成了200dp。
    • layout_height:组件的高度,内容同上。
    • gravity:设置控件中内容的对齐方向,TextView中是文字,ImageView中是图片等等。
    • text:设置显示的文本内容,一般我们是把字符串写到string.xml文件中,然后通过@String/xxx取得对应的字符串内容的,这里为了方便我直接就写到""里,不建议这样写!!!
    • textColor:设置字体颜色,同上,通过colors.xml资源来引用,别直接这样写!
    • textStyle:设置字体风格,三个可选值:**normal**(无效果),**bold**(加粗),**italic**(斜体)
    • textSize:字体大小,单位一般是用sp!
    • background:控件的背景颜色,可以理解为填充整个控件的颜色,可以是图片哦!

  • 相关阅读:
    一些不能订阅的前端学习资源
    酷站收集
    网页设计学习资源
    flash 内置类的位置
    打造自己的CodeSnippet (转)
    (转)打造自己的CodeSnippet
    WebApplication编程模型与WebSite编程模型
    (转).net面试问答(大汇总)
    ASP.NET 防盗链源码 (转)
    正则表达式基础知识
  • 原文地址:https://www.cnblogs.com/lxywsx/p/14907912.html
Copyright © 2020-2023  润新知