TextView特效

TextView特效

特效1 实现文字滚动效果的实现

      满足条件

  • 文本显示框的内容超过文本显示框的宽度
  • 文本显示框设置单行显示,即 
      android:singleLine="true"  默认情况下,超出宽度的文字会自动换行显示
  • 设置文字滚动显示,即
     android:ellipsize="marquee" 在单行情况下,超过文本显示框的部分默认不显示、
  • TextView 需要获取焦点,设置
            android:focusableInTouchMode="true" <pre name="code" class="html">        android:focusable="true" 单文本显示框失去焦点时,文本将不再移动
     

特效2自动链接效果的实现

        在Android应用中,特别是一些宣传页中,经常会使用到链接,单击链接后可以调用系统的相应程序来执行操作,例如网址链接、电话链接、邮箱链接等。在android中在TextView设置     android:autoLink="" 属性 即可,该属性有下面几个值。

  • none:不匹配任何格式,这是默认值
  • web  :只匹配网址,文本中的网址会以超链接的形式显示
  • map   : 只匹配地图地址
  • phone:只匹配电话号码
  • all      :匹配以上所有值


1 先看布局文件

Activity

<FrameLayout 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="${relativePackage}.${activityClass}" >

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:text="@string/hello_world"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:singleLine="true"
        android:textColor="#0000ff"
        android:textSize="24sp"
        android:layout_marginTop="20dp"
        />
    <TextView 
        android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:gravity="center"
        android:textSize="30sp"
        android:layout_gravity="center"
        android:text="@string/content"
        android:drawableTop="@drawable/ic_launcher"
        android:drawableBottom="@drawable/ic_launcher"
        android:drawableLeft="@drawable/ic_launcher"
        android:drawableRight="@drawable/ic_launcher"
        android:textColor="#0000ff"
        />
    <TextView 
        android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:text="@string/info"
		android:textColor="#ffffff"
		android:textSize="18sp"
		android:autoLink="all"        
		android:layout_gravity="bottom|center_horizontal"
		android:background="#0000ff"
		android:padding="5dp"        
        />

</FrameLayout>
2 string.xml文件
<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">TextViewEffect</string>
    <string name="hello_world">Hello world!</string>
    <string name="title">欢迎使用计算机科学与技术公司软件<font color=red>手机助手</font></string>
      <string name="content">零</string>
    <string name="info">如有问题请联系我们\n联系电话;0379-6909089\nE\-mail:wbf@qq.com\n网址:http://iet.github.cn</string>
</resources>
3.Activity代码
public class MainActivity extends Activity {
    private TextView mTitle;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mTitle=(TextView) findViewById(R.id.title);
        mTitle.setText(Html.fromHtml(getResources().getString(R.string.title)));
    }

运行效果
   
 

其它几个要点:

A.指定图片的方位

 android:drawableTop="@drawable/ic_launcher"
        android:drawableBottom="@drawable/ic_launcher"
        android:drawableLeft="@drawable/ic_launcher"
        android:drawableRight="@drawable/ic_launcher"

B. android:padding="5dp" 设置图片与文字的边距。

C.android:layout_gravity和android:gravity的使用区别 :android:gravity表示的是本控件里面的对齐方式,android:layout_gravity表示是该控件在其父控件中的对齐方式



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值