Customize the TextView to have a marquee effect

Source: Internet
Author: User

First, the introduction of the problem
Using the normal TextView horse racing effect, initially no focus events will not scroll, the button has focus events, but it is ugly, so you need to customize a TextView born with focus

Then you need to customize a TextView
Focusedtextview.java

 PackageCom.xuliugen.mobilesafe.ui;ImportAndroid.content.Context;ImportAndroid.util.AttributeSet;ImportAndroid.view.ViewDebug.ExportedProperty;ImportAndroid.widget.TextView;/** * Happy horse effect, start without focus event will not scroll * * Button has focus event, but it is ugly, so you need to customize a textview born with Focus * * @author Xuliugen * */ Public  class focusedtextview extends TextView {    /** * Custom view requires the following construction methods * * @param context * @param attrs * @param de Fstyle * *     Public Focusedtextview(context context, AttributeSet attrs,intDefstyle) {Super(Context, attrs, Defstyle); } Public Focusedtextview(context context, AttributeSet attrs) {Super(context, attrs); } Public Focusedtextview(Context context) {Super(context); }/** * Currently there is no focus, I just lied to the Android system */    @Override    @ExportedProperty(category ="Focus") Public Boolean isFocused() {return true; }}

Then we quote the following:

<!-- 跑马灯的效果 :滚动的textView-->    <com.xuliugen.mobilesafe.ui.FocusedTextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:ellipsize="marquee"        android:singleLine="true"        android:text="自定义TextView使之具有跑马灯的效果自定义TextView使之具有跑马灯的效果自定义TextView使之具有跑马灯的效果"        android:textSize="18sp" />

Customize the TextView to have a marquee effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.