`

TextView基本属性使用

阅读更多



注意:text1 text2 ... text7 text8中的...是表示text3 text 4直到text7,而不是真的...



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#eee"
android:orientation="vertical"
>
	<!-- 
		scrollbar是表示要显示的滚动条;但对于TextView来说滚动条只是一个装饰,只是显示了,没实际功能
		scrollHorizontally表示是否可以水平滚动,false的话就会换行
	-->
	<TextView
	android:layout_width="fill_parent"
	android:layout_height="40sp"
	android:background="#000"
	android:gravity="center"
	android:text="horizontial scrollbar test: text1 text2 text3 ... text7 text8"
	
	android:scrollHorizontally="true"
	android:scrollbars="horizontal"
	/>
	<TextView
	android:layout_width="fill_parent"
	android:layout_height="40sp"
	android:layout_marginTop="1sp"
	android:background="#000"
	android:gravity="center"
	android:text="vertical scrollbar test: text1 text2 text3 ... text7 text8 text9 text0"
	
	android:scrollbars="vertical|horizontal"
	android:textScaleX="1.8"
	/>
	<TextView
	android:layout_width="fill_parent"
	android:layout_height="40sp"
	android:layout_marginTop="1sp"
	android:background="#000"
	android:gravity="center_vertical"
	android:text="ellipsize and singleLine: text1 text2 text3 ... text7 text8 text9 text0"
	
	android:singleLine="true"
	android:ellipsize="middle"
	/>
	<TextView
	android:id="@+id/view"
	android:layout_width="fill_parent"
	android:layout_height="40sp"
	android:layout_marginTop="1sp"
	android:background="#000"
	android:gravity="center_vertical"
	android:text="ellipsize and line: text1 text2 text3 ... text7 text8 text9 text0"
	
	android:minLines="1"
	android:lines="1"
	android:maxLines="1"
	android:ellipsize="middle"
	/>
	<TextView
	android:layout_width="fill_parent"
	android:layout_height="40sp"
	android:layout_marginTop="1sp"
	android:background="#000"
	android:gravity="center_vertical"
	android:text="singleline test: text1 text2 text3 ... text7 text8 text9 text0"
	
	android:singleLine="true"
	/>
	<TextView
	android:layout_width="fill_parent"
	android:layout_height="40sp"
	android:layout_marginTop="1sp"
	android:background="#000"
	android:gravity="center_vertical"
	android:text="length:8 10 13 16 19 22 25"
	
	android:maxLength="20"
	/>
	<!--
	这个是因为设置了layout_width, layout_height,后面的width, height的设置就没起效果
	-->
	<TextView
	android:layout_width="fill_parent"
	android:layout_height="40sp"
	android:layout_marginTop="1sp"
	android:background="#000"
	android:gravity="center_vertical"
	android:text="width and height: text1 text2 text3 ... text7 text8 text9 text0"
	
	android:minWidth="10sp"
	android:width="20sp"
	android:maxWidth="30sp"
	
	android:minHeight="5sp"
	android:height="10sp"
	android:maxHeight="15sp"
	/>
	<TextView
	android:layout_width="fill_parent"
	android:layout_height="40sp"
	android:layout_marginTop="1sp"
	android:background="#000"
	android:gravity="center_vertical"
	android:text="text style test: text1 text2 text3 ... text7 text8 text9 text0"
	
	android:textColor="#f00"
	android:textStyle="bold"
	android:typeface="sans"
	/>
	<TextView
	android:layout_width="fill_parent"
	android:layout_height="40sp"
	android:layout_marginTop="1sp"
	android:background="#000"
	android:gravity="center_vertical"
	android:hint="hit text test: text1 text2 text3 text4"
	
	android:textColorHint="#0f0"
	android:typeface="monospace"
	android:textColorHighlight="#00f"
	/>
	<TextView
	android:layout_width="fill_parent"
	android:layout_height="40sp"
	android:layout_marginTop="1sp"
	android:background="#000"
	android:gravity="center_vertical"
	android:hint="link test: http://www.google.com.hk, google@gmail.com"
	
	android:linksClickable="true"
	android:autoLink="web|email"
	/>
</LinearLayout>


  • 大小: 26 KB
分享到:
评论

相关推荐

    TextView属性

    - `android:text`:这是设置`TextView`显示文本的基本属性,可以直接输入文本或者引用字符串资源。 2. **字体大小**: - `android:textSize`:用于设定文字的大小,单位可以是sp(可缩放像素),dp(密度独立像素...

    TextView属性详解

    在Android开发中,`TextView`作为最基本的文本显示组件,其丰富的属性配置为开发者提供了极大的灵活性。本文将详细解析`TextView`的重要属性,帮助开发者更好地理解和应用这些属性,提升应用程序的用户体验。 #### ...

    旋转TextView文字显示方向

    在Android开发中,TextView是用于显示文本的基本组件。然而,有时候我们可能需要让TextView中的文字以特定的角度旋转显示,比如垂直显示或者倾斜显示,来满足界面设计的需求。这就是"旋转TextView文字显示方向"这一...

    Android开发TextView排版问题取消自动换行

    首先,了解TextView的基本属性。TextView默认会根据其宽度自动进行换行,以适应屏幕布局。如果想取消自动换行,可以通过设置`android:singleLine`属性为`true`,在API 26及以上版本,这个属性被弃用,应使用`android...

    安卓textView相关-Android属性动画实现TextView类似支付宝余额数字滚动.rar

    在Android开发中,TextView是用于显示文本的基本组件,它的功能强大且灵活。在这个教程中,我们将探讨如何使用Android属性动画来实现一个类似支付宝余额数字滚动的效果。这种效果常见于金融应用,显示账户余额时,...

    使用TextView实现跑马灯效果

    首先,我们需要了解`TextView` 的基本属性和设置方法。在XML布局文件中,我们可以这样创建一个`TextView`: ```xml &lt;TextView android:id="@+id/my_marquee_text" android:layout_width="wrap_content" android:...

    安卓textView相关-TextView中文本的处理.rar

    在Android开发中,TextView是显示文本的基本控件,它的使用非常广泛,无论是显示简单的文字信息,还是复杂的格式化文本,TextView都是不可或缺的一部分。这个压缩包文件"安卓textView相关-TextView中文本的处理.rar...

    Android自定义属性实现带边框效果的TextView

    `android:`前缀则用于设置TextView的基本属性,如文字内容和尺寸。 通过这种方式,我们成功地实现了带边框效果的TextView。同时,由于使用了自定义属性,这个功能可以方便地在多个TextView实例间复用,提高了代码的...

    安卓textView相关-advanced-textview各种高级功能的textview.rar

    在Android开发中,TextView是用于显示文本的基本组件,它在用户界面中扮演着至关重要的角色。这个名为"advanced-textview各种高级功能的textview.rar"的压缩包显然包含了一些扩展了标准TextView功能的示例或者库。让...

    安卓textView相关-支持放大缩小的TextView使用.rar

    在Android开发中,TextView是用于显示文本的基本控件,它在用户界面中起着至关重要的作用。本资源“安卓textView相关-支持放大缩小的TextView使用.rar”似乎包含了一个定制的TextView实现,允许用户放大和缩小文本,...

    解决 TextView 中文、英文、数字、符号 排版问题

    为了解决这些问题,开发者需要对TextView的属性进行调整或使用特定的解决方案。 首先,我们要理解Android系统默认的文本渲染机制。Android系统基于Unicode编码处理各种语言,但不同的语言和字符类型有不同的间距...

    android TextView 支持CSS样式

    虽然原生的Android SDK并没有直接支持完整的CSS语法,但通过`TextView`的`setText`方法结合`Html.fromHtml()`函数,可以实现基本的HTML标签渲染,并且通过一些开源库或自定义处理方式,可以进一步扩展其功能,使其...

    TextView控件

    其基本属性包括文字内容(`text`)、文字颜色(`android:textColor`)、文字大小(`android:textSize`)、文字样式(如粗体、斜体等,通过`android:textStyle`设置)以及对齐方式(`android:textAlignment`)。...

    android TextView详解

    1. **TextView的基本使用** `TextView`是Android SDK中的一个视图类,继承自`View`或` ViewGroup`。在XML布局文件中,我们通常使用`&lt;TextView&gt;`标签来创建它,通过设置`android:text`属性来指定要显示的文本内容。 ...

    Android 实现TextView上下滚动效果

    要实现TextView的上下滚动,我们需要使用`android:singleLine`和`android:ellipsize`属性。`android:singleLine`属性设置为true,使得TextView只能显示一行文本,超出部分会被隐藏。`android:ellipsize`属性用于指定...

    旋转TextView文字显示

    在XML布局文件中,可以使用`android:rotation`属性来设置TextView的角度,单位为度(°)。例如,如果你希望文字逆时针旋转90度,可以这样写: ```xml &lt;TextView android:layout_width="wrap_content" android:...

    textview的展开和折叠

    首先,我们需要理解TextView的基本属性,如`android:singleLine`(已废弃)、`android:maxLines`和`android:ellipsize`。`android:singleLine`曾用于限制TextView为单行显示,但已被弃用,现在推荐使用`android:...

    可以展开的 TextView

    在Android开发中,TextView是用于显示文本的基本组件。然而,当文本内容过长时,我们通常需要限制TextView显示的字符数,或者提供一种方式让用户能够展开查看全部内容。"可以展开的TextView"就是一个解决此类问题的...

    自适应内容的TextView

    在Android开发中,TextView是用于显示文本的基本组件。在许多情况下,我们可能需要一个TextView能够自动适应其内容,无论内容的长度如何,都能保持宽度的一致性,这在设计整洁的用户界面时尤其重要。标题"自适应内容...

Global site tag (gtag.js) - Google Analytics