任务一 唐诗赏析软件

(1)TextView控件详解

Android中,文本框使用TextView表示,作用是在界面上显示文本。TextView提供了大量的XML属性,通过这些属性值的设置可以控制其显示内容的外观。表2-1显示了TextView常见的XML属性说明。TextView的基本语法格式如下:

<TextView

        属性列表

     />
例如:

<TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="佛祖保佑 永无BUG"

        android:textSize="25dp"

        android:textStyle="bold"/>

2-1TextView常见的XML属性列表

 

XML属性

android:autoLink

是否将符合指定格式的文本转换为可单击的超链接形式

adroid:id

设置该TextView的id

android:cursorVisible

设定光标为显示/隐藏,默认显示

android:digits

设置允许输入哪些字符。如“1234567890.+-*/% ()

android:gravity

设置文本位置,如设置成“center”,文本将居中显示

android:maxLength

限制显示的文本长度,超出部分不显示

android:lines

设置文本的行数,设置两行就显示两行,即使第二行没有数据

android:maxLines

设置文本的最大显示行数,与width或者layout_width结合使用,超出部分自动换行,超出行数将不显示

android:minLines

设置文本的最小行数

android:lineSpacingExtra

设置行间距

android:phoneNumber

设置为电话号码的输入方式

android:singleLine

设置单行显示。如果和layout_width一起使用,当文本不能全部显示时,后面用“…”来表示

android:text

设置显示文本

android:textColor

设置文本颜色

android:textSize

设置文字大小

android:textStyle

设置字形[bold(粗体) 0,italic(斜体) 1, bolditalic(又粗又斜) 2] 可以设置一个或多个,用“|”隔开

android:height

设置文本区域的高度

android:wight

设置文本区域的宽度

(2)文字填空题(1 分)

在空白处填入适当代码,实现字体加粗效果。

< TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="静夜思"

android:textSize="35dp"

____________________________

/ >
 Answer:android:textStyle="bold"

(3)线性布局知识点

为了更好管理Android应用中用户界面的组件,Android提供了布局管理器,它可以使应用的图形用户界面具有良好的平台无关性。通常推荐使用布局管理器来管理界面中组件的分布、大小。

线性布局使用LinearLayout类表示,它将放在其中的组件按照垂直或者水平方向来布局,也就是控制放入其中的组件横向或纵向排列。每一行或每一列中只能放一个组件,并且不能换行,当组件排列到窗体的边缘后,后面的组件将不会被显示出来。线性布局基本语法格式如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

   属性列表

> 

   组件列表

</LinearLayout>

                      2-2 LinearLayout常用XML属性列表

XML属性                                                                                                                                                                           

android:baselineAligned

如果该属性为false就会阻止该布局管理器与其子元素的基线对齐

android:divider

设置垂直布局时两个按钮之间的分隔条

android:gravity

设置布局管理器内组件(子元素)的对齐方式,支持属性有top bottomleftrightcenter_verticalcenter_horizontalfill_vertical fill_horizontalcenterfillclip_verticalclip_horizontal,可以同时指定多种对齐方式 ,如left|center_vertical 左侧垂直居中

android:orientation

设置布局管理器内组件排列方式设置为horizontal(水平),vertical(垂直), 默认为垂直排列


 

当在 Android 应用的 res/layout 目录下添加一个布局文件之后,可通过如下代码将其在 Activity 中显示。
setContentView(R.layout.布局文件名);
当在布局文件中添加多个组件,并通过 android:id 设定其唯一标识后,可通过如下代码对其进行访问。

 findViewById(R.id.组件id属性值);

(4)文字填空题

 
(1 分)

在画线处填入适当代码,实现两行文本纵向排列效果。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

      ———————————————

        android:gravity="center_horizontal"

        android:background="#FFFFFF">

        <TextView

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="举头望明月"

                android:textSize="25dp"

                android:textColor="#ff0000"

        />

        <TextView

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="低头思故乡"

                android:textSize="25dp"

                android:textColor="#ff0000"

        />

</LinearLayout>
ANSWER :android:orientation="vertical"



     

(5)实战代码、视频、截图

5.1界面编程实战1:实战视频,运行截图如下:

         

5.2相应XMl代码:

<?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"
    android:gravity="center_horizontal"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="佛祖保佑 永无BUG"
        android:textColor="#898383"
        android:textSize="25dp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Author:CYJ"
        android:textColor="#0f49e7"
        android:textSize="20dp"
        android:lineSpacingExtra="5dp"
        android:layout_marginBottom="5dp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="写字楼里写字间,写字间里程序猿;"
        android:textColor="#f10722"
        android:textSize="20dp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="程序人猿写程序,又拿程序换酒钱。"
        android:textColor="#f10722"
        android:textSize="20dp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="酒醒只在网上坐,酒醉还来网下眠;"
        android:textColor="#f10722"
        android:textSize="20dp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="酒醉酒醒日复日,网上网下年复年。"
        android:textColor="#f10722"
        android:textSize="20dp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="但愿老死电脑前,不愿鞠躬老板钱;"
        android:textColor="#f10722"
        android:textSize="20dp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="奔驰宝马富人趣,公交自行程序猿。"
        android:textColor="#f10722"
        android:textSize="20dp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="别人笑我太疯癫,我笑他人看不穿;"
        android:textColor="#f10722"
        android:textSize="20dp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="放眼满街单身狗,个个都是程序猿。"
        android:textColor="#f10722"
        android:textSize="20dp"
        />
</LinearLayout>

(6)源码链接   










  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云炬学长

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值