安卓——实现TextViewde的跑马灯效果
2018-02-23 19:25
330 查看
1.xml布局文件com.example.lenovo.marqueetextview.MarqueeText是我们写的MarqueeText这个类的路径
首先得把三个构造函数加上
然后覆写一下isFocused( )方法,让它一直返回true
这样xml文件里面的两个控件才会同时有跑马灯效果package com.example.lenovo.marqueetextview;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
/**
* Created by lenovo on 2018/2/23.
*/
public class MarqueeText extends TextView{
public MarqueeText(Context context){
super(context);
}
public MarqueeText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public MarqueeText(Context context, AttributeSet attrs) {
super(context, attrs);
}
/*
我们写的这个类中让所有View有焦点
*/
@Override
public boolean isFocused(){
return true;
}
}
3.MainActivitypackage com.example.lenovo.marqueetextview;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.lenovo.marqueetextview.MainActivity"> <com.example.lenovo.marqueetextview.MarqueeText android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" /> <com.example.lenovo.marqueetextview.MarqueeText android:id="@+id/textView2" android:layout_marginTop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" /> </RelativeLayout>2.Marquee继承TextView类
首先得把三个构造函数加上
然后覆写一下isFocused( )方法,让它一直返回true
这样xml文件里面的两个控件才会同时有跑马灯效果package com.example.lenovo.marqueetextview;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
/**
* Created by lenovo on 2018/2/23.
*/
public class MarqueeText extends TextView{
public MarqueeText(Context context){
super(context);
}
public MarqueeText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public MarqueeText(Context context, AttributeSet attrs) {
super(context, attrs);
}
/*
我们写的这个类中让所有View有焦点
*/
@Override
public boolean isFocused(){
return true;
}
}
3.MainActivitypackage com.example.lenovo.marqueetextview;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
相关文章推荐
- 安卓控件使用系列4:TextView实现跑马灯效果
- 安卓基础TextView跑马灯效果简单实现
- 用textview实现跑马灯效果
- 实现跑马灯效果的TextView
- android textView实现跑马灯效果
- 自定义View—实现滚动TextView(跑马灯)效果
- Android TextView实现滚动跑马灯效果Marquee
- Android使用TextView实现跑马灯效果
- TextView属性android:ellipsize实现跑马灯效果,TextView内容过长加省略号,点击显示全部内容
- 实现TextView跑马灯效果
- 使同一界面的多个textview实现跑马灯效果
- TextView实现跑马灯效果
- Android 高级UI设计笔记05:使用TextView实现跑马灯的效果
- Android中TextView不获取焦点可以实现跑马灯的效果
- 实现跑马灯效果的textview
- android自定义TextView实现安卓手机开机android文字Log的动画效果
- Android使用TextView实现跑马灯效果
- Android TextView实现跑马灯效果
- Android基于TextView不获取焦点实现跑马灯效果
- TextView实现跑马灯效果