利用MarqueeTextView实现上下公告栏并点击进行相应跳转
前言:例如某些淘宝商店里实现的上下公告栏,对其进行点击时会跳转到相应的界面
去。
viewFlipper
的为其动态添加相应
<?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="wrap_content" android:paddingTop="8dp" android:paddingBottom="8dp" android:orientation="horizontal"> <ViewFlipper android:id="@+id/viewFlipper" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:flipInterval="5000" android:padding="8dp" > </ViewFlipper> </LinearLayout>
MarqueeTextView
package com.example.com.mlsdome.Activity.Cuscontrols; import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.animation.AnimationUtils; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.ViewFlipper; import com.example.com.mlsdome.R; /** * Created by 12697 on 2017/3/27. */ public class MarqueeTextView extends LinearLayout {/* * 实现点击事件的两个参数 * */ private String[] textArrays; private MarqueeTextViewClickLisnter marqueeTextViewClickLisnter; private Context mcontext; private View marqueeTextView; /* * 上下滑动的效果 * * */ private ViewFlipper viewFlipper; public MarqueeTextView(Context context){super(context); this.mcontext=context; initBasicView(); }public MarqueeTextView(Context context, AttributeSet attrs){super(context, attrs); this.mcontext=context; initBasicView(); }/* * * 实现点击事件 * * */ public void setTextArraysAndClickListener(String[] textArrays,MarqueeTextViewClickLisnter marqueeTextViewClickLisnter){this.textArrays=textArrays; this.marqueeTextViewClickLisnter=marqueeTextViewClickLisnter; initMarqueeTextView(textArrays,marqueeTextViewClickLisnter); }/* * 如果textArrays长度为0是便返回 * * */ public void initMarqueeTextView(String[] textArrays,MarqueeTextViewClickLisnter marqueeTextViewClickLisnter){if (textArrays.length==0){return; }int i=0; viewFlipper.removeAllViews(); /* * 给viewflipper添加textview与layoutparams样式 * * */ while (i<textArrays.length){TextView textView=new TextView(mcontext); textView.setText(textArrays[i]); textView.setOnClickListener(marqueeTextViewClickLisnter); LayoutParams layoutParams=new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT); viewFlipper.addView(textView,layoutParams); i++; }}/* * 添加布局与为viewfilpper添加上下,左右动画 * * */ public void initBasicView(){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 releaseResources(){if (marqueeTextView != null){if (viewFlipper != null){viewFlipper.stopFlipping(); viewFlipper.removeAllViews(); viewFlipper = null; }marqueeTextView = null; }} }
package com.example.com.mlsdome.Activity.Cuscontrols; import android.view.View; /** * Created by 廖成康 on 2017/3/27. */ /* * * 实现接口 * * */ public interface MarqueeTextViewClickLisnter extends View.OnClickListener {void OnClick(View view); }
public MarqueeTextView(Context context) {super(context); this.mcontext=context; initBasicView(); }public MarqueeTextView(Context context, AttributeSet attrs) {super(context, attrs); this.mcontext=context; initBasicView(); }
public void initBasicView() {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(); }
viewFlipper
添加动画且对其进行开启
public void initMarqueeTextView(String[] textArrays,MarqueeTextViewClickLisnter marqueeTextViewClickLisnter) {if (textArrays.length==0){return; }int i=0; viewFlipper.removeAllViews(); /* * 给viewflipper添加textview与layoutparams样式 * * */ while (i<textArrays.length){TextView textView=new TextView(mcontext); textView.setText(textArrays[i]); textView.setOnClickListener(marqueeTextViewClickLisnter); LayoutParams layoutParams=new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT); viewFlipper.addView(textView,layoutParams); i++; } }
/* * * 实现点击事件 * * */ public void setTextArraysAndClickListener(String[] textArrays,MarqueeTextViewClickLisnter marqueeTextViewClickLisnter) {this.textArrays=textArrays; this.marqueeTextViewClickLisnter=marqueeTextViewClickLisnter; initMarqueeTextView(textArrays,marqueeTextViewClickLisnter); }
/* * 释放资源 * * */ public void releaseResources() {if (marqueeTextView != null){if (viewFlipper != null){viewFlipper.stopFlipping(); viewFlipper.removeAllViews(); viewFlipper = null; }marqueeTextView = null; } }
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="@android:integer/config_mediumAnimTime" android:fromYDelta="50%p" android:toYDelta="0" /> <alpha android:duration="@android:integer/config_mediumAnimTime" android:fromAlpha="0.0" android:toAlpha="1.0" /> </set>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="@android:integer/config_mediumAnimTime" android:fromYDelta="0" android:toYDelta="-50%p" /> <alpha android:duration="@android:integer/config_mediumAnimTime" android:fromAlpha="1.0" android:toAlpha="0.0" /> </set>
package com.example.com.mlsdome.Activity; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.View; import com.example.com.mlsdome.Activity.Cuscontrols.MarqueeTextView; import com.example.com.mlsdome.Activity.Cuscontrols.MarqueeTextViewClickLisnter; import com.example.com.mlsdome.R; /** * Created by 12697 on 2017/3/27. */ public class SignActivity extends ContextViewActivity {private String[] textArrays = new String[]{"this is content No.1","this is content No.2","this is content No.3"}; private MarqueeTextView marqueeTextView; @Override protected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState); setView(); showTitle("报名"); init(); marqueeTextView.setTextArraysAndClickListener(textArrays, new MarqueeTextViewClickLisnter() {@Override public void OnClick(View view){}@Override public void onClick(View view) {}}); }private void init(){marqueeTextView= (MarqueeTextView) findViewById(R.id.marqueeTv); }@Override public int setView(){return R.layout.sign_layout; }@Override protected void onDestroy() {marqueeTextView.releaseResources(); super.onDestroy(); } }
利用MarqueeTextView实现上下公告栏并点击进行相应跳转相关推荐
- 小程序轮播图swiper点击图片自定义跳转
我想实现的功能就是,点击首页的轮播图的不同图片,跳转到指定的页面. 点击轮播图的新用户专享图片跳转到新用户活动页面. 最开始我是想通过点击获取轮播图的下标,根据下标判断跳转到相应的页面,但是试了好久并 ...
- Chrome 插件开发-右键菜单开发实战演示,浏览器页面右键菜单选项设置,插件右键菜单点击插件名跳转主页设置
Chrome 插件开发 - 菜单选项 浏览器页面右键菜单选项设置 ① 核心代码演示 ② 效果展示 ③ 详细参数文档 插件右键菜单点击插件名跳转主页设置 ① 核心代码演示 ② 演示效果图 浏览器页面右键 ...
- PHP——0128练习相关2——js点击button按钮跳转到另一个新页面
js点击button按钮跳转到另一个新页面 投稿:whsnow 字体:[增加 减小] 类型:转载 时间:2014-10-10 我要评论 点击按钮怎么跳转到另外一个页面呢?点击图片要跳转到新的页面时,怎 ...
- 解密-大象跳转如何实现微信中点击链接直接跳到默认浏览器(不是在微信内置浏览器打开)
很多朋友不知道如何实现微信中点击链接直接跳到默认浏览器的功能是如何实现,经常能在各大论坛看到这样的提问,故特写了这篇文章分享一下之前在网上看到的一个在线使用该功能的平台的操作方法. 大象跳转在线操作步 ...
- 解决vue项目路由出现message: “Navigating to current location (XXX) is not allowed“的问题(点击多次跳转)
解决vue项目路由出现message: "Navigating to current location (XXX) is not allowed"的问题(点击多次跳转) 参考文章: ...
- android原生代码转h5,Android原生和H5交互;Android和H5混合开发;WebView点击H5界面跳转到Android原生界面。...
当时业务的需求是这样的,H5有一个活动商品列表的界面,IOS和Android共用这一个界面,点击商品可以跳转到Android原生的商品详情界面并传递商品ID: 大概就是点击H5界面跳转到Androi ...
- Android--(三星手机)webview嵌套H5,点击H5按钮跳转手机拍照,横屏拍照导致失败或崩溃问题
Android--(三星手机)webview嵌套H5,点击H5按钮跳转手机拍照,横屏拍照导致失败或崩溃问题(完美解决) 最近在改一个需求,用的是第三方公司的一个H5链接(Udesk公司),发现WebV ...
- A链接点击下载不跳转页面
a链接点击下载不跳转页面 要求:点击按钮在当前页面下载,并且不能跳转 直接代码: $('.btn_xz').click(function(){// 添加一个a标签let ele = document. ...
- echarts,map中国地图点击各省,跳转展示,从省返回到中国地图【china.js】
效果图: 1.点击省,跳转到河北省 2.返回,从省返回到中国地图 话不多说,直接上代码,1.复制粘贴,2.在引入对应js即可 注:全部各省地图,下载地址:** <!DOCTYPE html> ...
最新文章
- 新生替代Reflector的反编译软件ILSpy
- JSF优点(转载自中国IT实验室)
- php根据当前日期判断法定节假日_判断日期是否为法定节假日的API接口与示例函数...
- 来之不易的美团面试,结果居然挂了...(附面试答案)
- World Cup 996B(排队模拟)
- 美网络司令部:马上修复严重的 PAN-OS 漏洞,免遭国家黑客攻击
- 桌面计算机主流硬盘接口,M.2、U.2谁更好?主流硬盘接口大扫盲
- 查询SQL Server中表占用的空间方法
- 如何将背景音乐添加到iMovie?
- C双拼输入法使用说明
- LOAP引擎:clickhouse 01: 介绍、安装及集群搭建
- 2021年茶艺师(中级)考试内容及茶艺师(中级)找解析
- SFDC common errors
- sparse coding
- 苹果EMS物流管理系统
- 欧姆龙程序PLC案例标准程序 使用欧姆龙CP1H写的脉冲伺服 步进控制程序案例
- xiaopiu怎么导出html,xiaopiu原型工具
- 武汉大学计算机学院 优秀夏令营,武汉大学计算机学院2014年优秀大学生暑期夏令营通知.docx...
- Codeforces Round #451 (Div. 2)
- [乐意黎转载]关于泸西县弯腰树村委会经济社会发展思路调研报告
热门文章
- 替代兼容矽力杰SY6982E双电池5V升压锂离子电池充电器充电IC
- 【程序计数器】概念、作用、特点、线程私有、本地方法的概述_JVM02
- 初中C语言教程,初中信息学竞赛C语言程序设计基础入门教学视频全集(万门学院 23讲)...
- php+mysql新闻系统的开发一_基于PHP+mysql实现新闻发布系统的开发
- 项目使用计算机上目前不可用的字体,muruoxi-Check-Font-Copyright
- 在一段文字中统计某个字出现的次数
- ios 打印c语言数组,第07天C语言(07):数组练习3
- Oracle 数据库12c 16大新特性总结
- sqlyog怎么连接mysql_Windows Server系统部署MySQL数据库
- 中文翻译韩文软件有哪些?