大作业之小无聊------TextView跑马灯推送消息

     无聊之中学习,好好玩

     目的 :在屏幕上方推送消息,一直无限循环推送

一 实验效果图:

1.单行:


2.多行:




二:实验步骤:


1.修改helloword  



效果图:

2.让其单行显示,显示成跑马灯效果:


效果图:




3.再加一个TextView:



效果图:



结果:
第一行是跑马灯效果,第二行不是,第二行整行显示。

4.创建一个类:



修改包名:



效果图:




三。核心代码:


<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <com.example.liu1.OtherText
        android:id="@+id/TextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee" 
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:singleLine="true"
        android:text="@string/hello_world" />
    <com.example.liu1.OtherText
        android:layout_below="@id/TextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee" 
        android:focusable="true"
        android:layout_marginTop="10dp"
        android:focusableInTouchMode="true"
        android:singleLine="true"
        android:text="@string/hello_world" />


</RelativeLayout>
2.OtherTextView.java

package com.example.liu1;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;

public class OtherText extends TextView{

	public OtherText(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public OtherText(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	public OtherText(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}


	@Override
	public boolean isFocused(){
		return true;
	}
	
	
}

3 string.xml

<resources>

    <string name="app_name">Liu1</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">我是刘鲁南,我是刘鲁南,我是刘鲁南,我是刘鲁南,我是刘鲁南,大好人。</string>

</resources>

四。总结:

  单行跑马灯还是很容易的,多行跑马灯如果用前面的思路直接导致聚焦在第一行,第二行不动,看视频看出建一个类,里面有很多东西也没有搞懂,特别是add东西的时候


        android:ellipsize="marquee" 跑马灯
        android:focusable="true"    聚焦
        android:focusableInTouchMode="true"  设置焦点联系方式
        android:singleLine="true"   单行显示

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值