2_1.8_跑马灯_滚动新闻_广告_

activity_marquee.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下面演示跑马灯"
android:layout_marginTop="50dp"
android:textSize="36sp"
/>

<TextView
android:id="@+id/tvMarquee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:ellipsize="marquee"
android:singleLine="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:textSize="24sp"
android:text="快讯:预警信息,台风来袭,请注意防汛信息。台风来袭,请注意防汛信息台风来袭,请注意防汛信息台风来袭,请注意防汛信息台风来袭,请注意防汛信息" />


</LinearLayout>

 

-------------------------------------------------

MarqueeActivity.java

package com.example.dfby.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MarqueeActivity extends AppCompatActivity {
private TextView tvMarquee;
private boolean isPause=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_marquee);
tvMarquee=findViewById(R.id.tvMarquee);
tvMarquee.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(isPause){
tvMarquee.setFocusable(true);
tvMarquee.setFocusableInTouchMode(true);
}else{
tvMarquee.setFocusable(false);
tvMarquee.setFocusableInTouchMode(false);
}
isPause=!isPause;
}
});


}
}

posted @ 2019-01-09 12:02  小庄啊  阅读(116)  评论(0编辑  收藏  举报