Tears_fg

导航

Android_TextVIew_flow_ex1

xml文件:

<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="com.example.app6.MainActivity" >

    <com.example.TextView_flow.marqueeText
        android:id="@+id/textView_1"
        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"/>
    <!--  TextView可以用其子类来声明,子类的表现形式是包名+类名
            设置4条语功能语句才能实现跑马灯的效果-->
    <com.example.TextView_flow.marqueeText
        android:layout_below="@id/textView_1"
        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>

marqueeText.java

package com.example.TextView_flow;

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

public class marqueeText extends TextView{

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

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

    public marqueeText(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }
    /*
     * 复写这个方法是第一个文本框得到了可聚焦为true的方法,以跑马灯形式显示,而其他文本框得不到
     */
    @Override
    public boolean isFocused() {
        return true;
    }
}

源代码:

package com.example.TextView_flow;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

 

posted on 2016-06-14 13:21  Tears_fg  阅读(186)  评论(0编辑  收藏  举报