首页 > 编程语言 >直播app源码开源,Android 滚动的公告栏

直播app源码开源,Android 滚动的公告栏

时间:2023-11-09 14:26:34浏览次数:37  
标签:公告栏 LayoutParams app textArrays private viewFlipper 源码 void public

直播app源码开源,Android 滚动的公告栏

 

public class MarqueeTextView extends LinearLayout {
 
    private Context mContext;
    private ViewFlipper viewFlipper;
    private View marqueeTextView;
    private String[] textArrays;
    private MarqueeTextViewClickListener marqueeTextViewClickListener;
 
    public MarqueeTextView(Context context) {
        super(context);
        mContext = context;
        initBasicView();
    }
 
 
    public MarqueeTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        initBasicView();
    }
 
    public void setTextArraysAndClickListener(String[] textArrays, MarqueeTextViewClickListener marqueeTextViewClickListener) {//1.设置数据源;2.设置监听回调(将textView点击事件传递到目标界面进行操作)
        this.textArrays = textArrays;
        this.marqueeTextViewClickListener = marqueeTextViewClickListener;
        initMarqueeTextView(textArrays, marqueeTextViewClickListener);
    }
 
    public void initBasicView() {//加载布局,初始化ViewFlipper组件及效果
        marqueeTextView = LayoutInflater.from(mContext).inflate(R.layout.marquee_textview_layout, null);
        LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        addView(marqueeTextView, layoutParams);
        viewFlipper = (ViewFlipper) marqueeTextView.findViewById(R.id.viewFlipper);
        viewFlipper.setInAnimation(AnimationUtils.loadAnimation(mContext, R.anim.slide_in_bottom));//设置上下的动画效果(自定义动画,所以改左右也很简单)
        viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(mContext, R.anim.slide_out_top));
        viewFlipper.startFlipping();
    }
 
    public void initMarqueeTextView(String[] textArrays, MarqueeTextViewClickListener marqueeTextViewClickListener) {
        if (textArrays.length == 0) {
            return;
        }
 
        int i = 0;
        viewFlipper.removeAllViews();
        while (i < textArrays.length) {
            TextView textView = new TextView(mContext);
            textView.setText(textArrays[i]);
            textView.setOnClickListener(marqueeTextViewClickListener);
            LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            viewFlipper.addView(textView, lp);
            i++;
        }
    }
 
    public void releaseResources() {
        if (marqueeTextView != null) {
            if (viewFlipper != null) {
                viewFlipper.stopFlipping();
                viewFlipper.removeAllViews();
                viewFlipper = null;
            }
            marqueeTextView = null;
        }
    }
 
}

 

然后,主Activity异常简单(还是封装得好):

 


 
public class MainActivity extends AppCompatActivity {
    private MarqueeTextView marqueeTv;
    private String [] textArrays = new String[]{"this is content No.1","this is content No.2","this is content No.3"};
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        marqueeTv = (MarqueeTextView) findViewById(R.id.marqueeTv);
 
        marqueeTv.setTextArraysAndClickListener(textArrays, new MarqueeTextViewClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MainActivity.this,AnotherActivity.class));
            }
        });
    }
 
    @Override
    protected void onDestroy() {
        marqueeTv.releaseResources();
        super.onDestroy();
    }
}

 

 

 以上就是 直播app源码开源,Android 滚动的公告栏,更多内容欢迎关注之后的文章

 

标签:公告栏,LayoutParams,app,textArrays,private,viewFlipper,源码,void,public
From: https://www.cnblogs.com/yunbaomengnan/p/17819620.html

相关文章

  • 基于Vant Weapp的生日管家
    目前市面上提供了一些免费开源的第三方小程序UI组件库,可以下载后放到项目文件夹中直接使用,比起开发者从头开始自定义组件更为方便、高效。本次考虑使用第三方UI组件来实现界面的视觉统一。本次以有赞第三方UI组件库VantWeapp为例,介绍如何使用自定义组件配合云开发中的数据库基本......
  • 直播app系统源码,python pdf转为图片
    直播app系统源码,pythonpdf转为图片 fromwand.imageimportImageimportos#将pdf文件转为jpg图片文件cur_file_path=os.path.dirname(os.path.realpath(__file__))#path为pdf文件路径path=os.path.join(cur_file_path,os.pardir,'ehouse/resource/img/')image_pdf=......
  • Flink(一):flink源码&&导入到IDE
    一、获取源码1、从Git克隆代码gitclonehttps://github.com/apache/flink.git2、maven运行编译mvncleaninstall-DskipTests注:为了加速构建,可以执行如下命令,以跳过测试,QA的插件和JavaDocs的生成:mvncleaninstall-DskipTests-Dfast 二、环境......
  • easyEZbaby_app
    for循环,这里给它化简255-i+2-98-未知数x需要等于'0'对应的ASCII值48,那么求x的值,x=111-i,而i的值就是从0到14,这样便可以计算出15位的密码 所以写出来的脚本 ......
  • ASP.NET Ajax exception - Two components with the same id can't be added to the a
    There'sacoupleofexceptionstolookoutforwhenyoustartdevelopingcustomASP.NETAjaxclientcontrols. Theyare:MicrosoftJScriptruntimeerror:Sys.InvalidOperationException:Twocomponentswiththesameid'ctl00_MainContentPlaceHold......
  • Spring RMI实现远程调用及源码
    1.RMI简单介绍Spring除了使用基于HTTP协议的远程调用方案,还为开发者提供了基于RMI机制的远程调用方法,RMI远程调用网络通信实现是基于TCP/IP协议完成的,而不是通过HTTP协议。在SpringRMI实现中,集成了标准的RMI-JRIM解决方案,该方案是java虚拟机实现的一部分,它使用java序列化来完成对......
  • 多人语音聊天与视频交友APP,开启社交新时代!
     引领潮流,社交新风尚你是否厌倦了传统的社交方式?是否期待与全球各地的小伙伴一起畅所欲言、分享快乐?我们为你带来全新的多人语音聊天和视频交友APP,让你感受前所未有的社交体验,成为引领社交新时代的潮流先锋!功能强大,满足多元需求多人语音畅聊:无论你是与朋友相聚,还是与家人团圆......
  • uni-app vue3 获取元素报错问题
    关于uniapp中vue3使用uni.createSelectorQuery()时的this指向及查询结果说明_前端_谁凉了时光旧了少年-华为云开发者联盟(csdn.net)......
  • 用户信息授权报错“无效的AppID参数”问题排查解决过程
    今天记一个支付宝报错“无效的AppID参数”的问题排查解决过程,希望可以帮到大家。报错产生今天在测试支付宝用户信息授权换取授权访问令牌的时候,遇到了一个报错:“无效的AppID参数”,本来以为是个简单的问题,结果还是花了一点时间去找原因,找到最后发现是自己脑子瓦特了=。=报错......
  • No MyBatis mapper was found in ‘[SpringBoot启动类所在路径]‘ package 原因解析及
    NoMyBatismapperwasfoundin‘[SpringBoot启动类所在路径]‘package原因解析及解决方案NoMyBatismapperwasfoundin'[XXX]'package友情提示:搜到这篇文章的,一般是急于解决这个问题的,看下常见原因排除后,可以忽略分析过程直接看解决方案,我自己出现这个问题的原因主......