use of com.sunfusheng.marqueeview.MarqueeView in project MarqueeView by sfsheng0322.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
marqueeView = (MarqueeView) findViewById(R.id.marqueeView);
marqueeView1 = (MarqueeView) findViewById(R.id.marqueeView1);
marqueeView2 = (MarqueeView) findViewById(R.id.marqueeView2);
marqueeView3 = (MarqueeView) findViewById(R.id.marqueeView3);
marqueeView4 = (MarqueeView) findViewById(R.id.marqueeView4);
List<CharSequence> list = new ArrayList<>();
SpannableString ss1 = new SpannableString("1、MarqueeView项目");
ss1.setSpan(new ForegroundColorSpan(Color.RED), 2, 13, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
list.add(ss1);
SpannableString ss2 = new SpannableString("2、GitHub:sfsheng0322");
ss2.setSpan(new ForegroundColorSpan(Color.GREEN), 9, 20, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
list.add(ss2);
SpannableString ss3 = new SpannableString("3、个人博客:sunfusheng.com");
ss3.setSpan(new URLSpan("http://sunfusheng.com/"), 7, 21, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
list.add(ss3);
list.add("4、孙福生微博,请粉哦");
marqueeView.startWithList(list);
marqueeView1.startWithText(getString(R.string.marquee_texts));
marqueeView2.startWithText(getString(R.string.marquee_texts));
marqueeView3.startWithText(getString(R.string.marquee_texts));
marqueeView4.startWithText(getString(R.string.marquee_text));
marqueeView.setOnItemClickListener(new MarqueeView.OnItemClickListener() {
@Override
public void onItemClick(int position, TextView textView) {
Toast.makeText(getApplicationContext(), textView.getText() + "", Toast.LENGTH_SHORT).show();
}
});
marqueeView1.setOnItemClickListener(new MarqueeView.OnItemClickListener() {
@Override
public void onItemClick(int position, TextView textView) {
Toast.makeText(getApplicationContext(), String.valueOf(marqueeView1.getPosition()) + ". " + textView.getText(), Toast.LENGTH_SHORT).show();
}
});
}
use of com.sunfusheng.marqueeview.MarqueeView in project MarqueeView by sfsheng0322.
the class CommonFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tab, container, false);
marqueeView = view.findViewById(R.id.marqueeView);
marqueeView1 = view.findViewById(R.id.marqueeView1);
marqueeView2 = view.findViewById(R.id.marqueeView2);
marqueeView3 = view.findViewById(R.id.marqueeView3);
marqueeView4 = view.findViewById(R.id.marqueeView4);
List<CharSequence> list = new ArrayList<>();
SpannableString ss1 = new SpannableString("1、MarqueeView开源项目");
ss1.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.red)), 2, 13, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
list.add(ss1);
SpannableString ss2 = new SpannableString("2、GitHub:sunfusheng");
ss2.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.blue)), 9, 19, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
list.add(ss2);
SpannableString ss3 = new SpannableString("3、个人博客:sunfusheng.com");
ss3.setSpan(new URLSpan("http://sunfusheng.com/"), 7, 21, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
list.add(ss3);
list.add("4、新浪微博:@孙福生微博");
// set Custom font
marqueeView.setTypeface(ResourcesCompat.getFont(getContext(), R.font.huawenxinwei));
marqueeView.startWithList(list);
marqueeView.setOnItemClickListener((position, textView) -> Toast.makeText(getContext(), textView.getText() + "", Toast.LENGTH_SHORT).show());
marqueeView1.startWithText(getString(R.string.marquee_texts), R.anim.anim_top_in, R.anim.anim_bottom_out);
marqueeView1.setOnItemClickListener((position, textView) -> Toast.makeText(getContext(), String.valueOf(position) + ". " + textView.getText(), Toast.LENGTH_SHORT).show());
marqueeView2.startWithText(getString(R.string.marquee_text));
marqueeView3.startWithText(getString(R.string.marquee_texts));
marqueeView3.setOnItemClickListener((position, textView) -> {
CharSequence model = (CharSequence) marqueeView3.getMessages().get(position);
Toast.makeText(getContext(), model, Toast.LENGTH_SHORT).show();
});
List<CustomModel> models = new ArrayList<>();
models.add(new CustomModel(10000, "增加了新功能:", "设置自定义的Model数据类型"));
models.add(new CustomModel(10001, "GitHub:sunfusheng", "新浪微博:@孙福生微博"));
models.add(new CustomModel(10002, "MarqueeView开源项目", "个人博客:sunfusheng.com"));
marqueeView4.startWithList(models);
marqueeView4.setOnItemClickListener((position, textView) -> {
CustomModel model = (CustomModel) marqueeView4.getMessages().get(position);
Toast.makeText(getContext(), "ID:" + model.id, Toast.LENGTH_SHORT).show();
});
return view;
}
Aggregations