我就不bb了,直接上代码了
云端给我传的是一个json数组嘛,我只要取其中某个指定字符,取完后,加到一个string里面,中间用空格隔开,就可以了,很多开源的,满足不了朴实的要求,没办法~
package cn.titansys.fowlet.ui.textview;
import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import com.alibaba.fastjson.JSON;
import java.util.ArrayList;
import java.util.List;
import cn.titansys.fowlet.data.json.DeviceParse;
import cn.titansys.fowlet.model.iSubtitles;
import cn.titansys.fowlet.ui.marquee.CustomerMarqueeView;
public class TextRoll {
private TextView textView;
private Activity activity;
private DeviceParse deviceParse;
private List<String> stringList = new ArrayList<String>();
public TextRoll(TextView textView, Activity activity){
this.textView =textView;
this.activity =activity;
deviceParse = new DeviceParse(activity);
}
public void Show(String html){
CharSequence charSequence = Html.fromHtml(html);
textView.setText(charSequence);
textView.setMovementMethod(LinkMovementMethod.getInstance());//添加链接
textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);//最多几行
textView.setSingleLine(true);
textView.setSelected(true);
textView.setFocusable(false);
textView.setFocusableInTouchMode(false);
}
public void goDo(){
//Log.e("stringList","smv+"+deviceParse.get_data_app_extra_subtitles());
if(deviceParse.get_data_app_extra_subtitles()==null){
textView.setVisibility(View.GONE);
Log.e("stringList","smv+null");
return;
}
textView.setVisibility(View.VISIBLE);
List<iSubtitles> subc = JSON.parseArray(deviceParse.get_data_app_extra_subtitles(), iSubtitles.class);
for (iSubtitles pp : subc) {
// pp.getContent()
// pp.getName()
// pp.isEnable()
if(pp.isEnable()){
stringList.add(pp.getContent());
Log.e("stringList","smv"+stringList.size()+"str"+pp.getContent());
}
}
if(stringList.size()==0){
textView.setVisibility(View.GONE);
}else {
String str = "";
for (int i = 0; i < stringList.size(); i++) {
//System.out.println(stringList.get(i));
str = str + "\t\t\t\t\t\t\t\t\t\t\t\t\t" + stringList.get(i);
}
Show(str);
}
}
}
使用
public void barrage(TextView tv_hint) {
TextRoll textRoll = new TextRoll(tv_hint, activity);
textRoll.goDo();
}
布局
<TextView
android:visibility="gone"
android:id="@+id/tv_hint"
android:textColor="@color/color_white"
android:textSize="30dp"
android:textStyle="bold"
android:gravity="center_vertical"
android:background="#283747"
android:marqueeRepeatLimit="marquee_forever"
android:layout_width="match_parent"
android:layout_height="40dp"/>