第一行代码:Android(第二版)——第三章笔记(一)

本文主要介绍了Android开发中的常用控件,包括TextView、Button、EditText和ImageView的使用方法。详细讲解了Button的资源文件创建、事件处理,以及EditText与Button结合的案例。此外,还提到了ImageView在展示图片上的应用。
摘要由CSDN通过智能技术生成

参考书籍:第一行代码:Android(第二版)(郭霖):第三章

一、常用控件使用方法

1、初学暂时使用的布局

<?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">
</LinearLayout>

2、TextView

TextView可以说是Android中最简单的一个控件,它主要用于在界面上显示一段文本信息,比如第一章中的HelloWorld,更多的使用方法如下

<!--
android:id:该组件的唯一标识符
android:layout_width:宽
android:layout_height:高
    三个值可选:match_parent(当前控件的大小和父布局一样)、fill_parent(意思同上)、wrap_content(当前控件的大小刚好包含住里面的内容)
android:text:指定在TextView中显示的文本内容(文字默认是居左上角对齐)
android:gravity:指定组件内文字的对齐方式,可选top\bottom\left\right\center等
    可以用"|"来同时指定多个值,center的效果等同于center_vertical|center_horizontal(竖直和水平都居中)
android:textSize:设置文字的大小(sp为单位)
android:textColor:设置文字颜色
android:textStyle:设置字体风格:italic(斜体),bold(加粗),normal(默认)
android:background:设置控件的背景颜色
android:shadowColor:设置阴影颜色,需要与shadowRadius一起使用
android:shadowDx:设置阴影再说水平方向的偏移,就是水平方向阴影开始的横坐标位置
android:shadowDy:设置阴影再说竖直方向的偏移,就是水平方向阴影开始的纵坐标位置
android:shadowRadius:设置阴影的模糊程序,设为0.1就变成字体颜色,建议使用3.0
跑马灯如下:
android:singleLine:内容单行显示
android:focusable:是否可以获取焦点
android:focusableInTouchMode:用于控制视图在触摸模式下是否可以聚焦
android:ellipsize:在哪里省略文本(marquee滚动、start省略号在前面、end省略号在后面、middle省略号在中间、none)
 android:marqueeRepeatLimit:字幕动画重复的次数marquee_forever无限次数
 以下代码实现跑马灯
-->
    <TextView
        android:id="@+id/text_view"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:gravity="center"
        android:text="HelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorld"
        android:background="#BBC8C3"
        android:textStyle="italic"
        android:textSize="24sp"
        android:textColor="#229000FF"
        android:shadowColor="@color/purple_700"
        android:shadowDx="15.0"
        android:shadowDy="15.0"
        android:shadowRadius="10.0"
        android:singleLine="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:ellipsize="marquee"
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

废材终结者

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

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

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

打赏作者

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

抵扣说明:

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

余额充值