




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】Android中怎么实现京东快报无限轮播效果
Android中怎么实现京东快报无限轮播效果?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。public
class
NoticeView
extends
ViewFlipper
implements
View.OnClickListener
{
private
Context
mContext;
private
List<String>
mNotices;
private
OnNoticeClickListener
mOnNoticeClickListener;
public
NoticeView(Context
context)
{
super(context);
}
public
NoticeView(Context
context,
AttributeSet
attrs)
{
super(context,
attrs);
init(context);
}
private
void
init(Context
context)
{
mContext
=
context;
//
轮播间隔时间为3s
setFlipInterval(3000);
//
内边距5dp
setPadding(dp2px(5f),
dp2px(5f),
dp2px(5f),
dp2px(5f));
//
设置enter和leave动画
setInAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.notice_in));
setOutAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.notice_out));
}
/**
*
添加需要轮播展示的公告
*
*
@param
notices
*/
public
void
addNotice(List<String>
notices)
{
mNotices
=
notices;
removeAllViews();
for
(int
i
=
0;
i
<
mNotices.size();
i++)
{
//
根据公告内容构建一个TextView
String
notice
=
notices.get(i);
TextView
textView
=
new
TextView(mContext);
textView.setSingleLine();
textView.setText(notice);
textView.setTextSize(20f);
textView.setEllipsize(TextUtils.TruncateAt.END);
textView.setTextColor(Color.parseColor("#666666"));
textView.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL);
//
将公告的位置设置为textView的tag方便点击是回调给用户
textView.setTag(i);
textView.setOnClickListener(this);
//
添加到ViewFlipper
NoticeView.this.addView(textView,
new
LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
}
}
@Override
public
void
onClick(View
v)
{
int
position
=
(int)
v.getTag();
String
notice
=
(String)
mNotices.get(position);
if
(mOnNoticeClickListener
!=
null)
{
mOnNoticeClickListener.onNotieClick(position,
notice);
}
}
/**
*
通知点击监听接口
*/
public
interface
OnNoticeClickListener
{
void
onNotieClick(int
position,
String
notice);
}
/**
*
设置通知点击监听器
*
*
@param
onNoticeClickListener
通知点击监听器
*/
public
void
setOnNoticeClickListener(OnNoticeClickListener
onNoticeClickListener)
{
mOnNoticeClickListener
=
onNoticeClickListener;
}
private
int
dp2px(float
dpValue)
{
return
(int)
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
dpValue,
mContext.getResources().getDisplayMetrics());
}
}布局文件<?xml
version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20sp"
android:layout_marginLeft="15sp"
android:layout_marginRight="15sp"
android:layout_marginTop="20sp"
android:background="@drawable/jingdong_news_bgcolor"
android:orientation="horizontal"
android:paddingLeft="15sp"
android:paddingRight="15sp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/jd_news_tit"
/>
<ject.jingdong.customview.NoticeView
android:id="@+id/notice_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="1"></ject.jingdong.customview.NoticeView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:text="
|
更多
"
android:textSize="22sp"
/>
</LinearLayout>布局的样式<?xml
version="1.0"
encoding="utf-8"?><!--
定义圆角矩形
-->
<shape
xmlns:android="/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<!--
填充颜色
-->
<solid
android:color="#FFFFFF"
/>
<!--
圆角
-->
<corners
android:bottomLeftRadius="16dp"
android:bottomRightRadius="16dp"
android:topLeftRadius="16dp"
android:topRightRadius="16dp"
/>
<!--
边框颜色
-->
<stroke
android:width="1dip"
android:color="#FFFFFF"
/>
</shape>公告内容进入动画notice_in.xml<?xml
version="1.0"
encoding="utf-8"?>
<set
xmlns:android="/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>公告内容滑出动画notice_out.xml<?xml
version="1.0"
encoding="utf-8"?>
<set
xmlns:android="/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>在Activity或者Fragment中直接使用就可以了
//定义成为一个方法,直接调用就行了
private
void
init()
{
NoticeView
noticeView
=
(NoticeView)
getActivity().fi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 初中历史散文支架式教学研究
- 鄂尔多斯市乌审旗民间展览馆的博物馆人类学研究
- 社交网络在老年人健康管理与教育中的应用研究
- 河套灌区向日葵农田土壤氨挥发及冠层氨通量对不同农业管理措施的响应
- 陕西阎良方言体系统研究
- 基于二极管的工作点和束流位置测量技术的研究
- 肥胖人群内脂脂肪面积与胰岛素抵抗相关性研究
- 木质工艺家具企业ESG实践与创新战略研究报告
- 男休闲鞋企业县域市场拓展与下沉战略研究报告
- 鸟苷企业县域市场拓展与下沉战略研究报告
- 指导青年教师课堂教学活动方案
- 一年级美术课后辅导方案-1
- 免疫学基础与病原生物学课件
- 2022版义务教育(地理)课程标准(附课标解读)
- 《锻造安全生产》课件
- 中考英语阅读理解(含答案)30篇
- 文化产业管理专业大学生职业生涯规划书
- DSM-V美国精神疾病诊断标准
- 文献的载体课件
- 2023年高考语文全国乙卷《长出一地的好荞麦》解析
- 混凝土强度回弹检测方案
评论
0/150
提交评论