Android仿淘宝头条基于TextView实现上下滚动通知效果
2017-03-10 09:52
1081 查看
最近有个项目需要实现通知栏的上下滚动效果,仿淘宝头条的那种。
我从网上看了一些代码,把完整的效果做了出来。如图所示:
具体代码片段如下:
1.在res文件夹下新建anmin文件夹,在这个文件夹里创建两个文件
(1).anim_marquee_in.xml进入时动画
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="1500" android:fromYDelta="100%p" android:toYDelta="0"> </translate> </set>
(2).anim_marquee_out.xml退出时动画
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="1500" android:fromYDelta="0" android:toYDelta="-100%p"> </translate> </set>
2.activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.spore.marqueeview.MainActivity" > <ViewFlipper android:id="@+id/marquee_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:autoStart="true" android:background="#fff" android:flipInterval="2500" android:inAnimation="@anim/anim_marquee_in" android:outAnimation="@anim/anim_marquee_out" > </ViewFlipper> </RelativeLayout>
3.noticelayout.xml
<?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:orientation="horizontal" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dp" android:src="@drawable/icon_home_notice" /> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_vertical" android:paddingLeft="10dp" android:singleLine="true" android:text="[2017-02-28 08:00]通知:上午九点整开会!" android:textSize="18sp" /> </LinearLayout>
4.MainActivity.java
package com.iponkan.textviewupdown; import com.example.textviewupdown.R; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.ViewFlipper; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 为ViewFlipper添加广告条 ViewFlipper vf = (ViewFlipper) findViewById(R.id.marquee_view); vf.addView(View.inflate(this, R.layout.noticelayout, null)); vf.addView(View.inflate(this, R.layout.noticelayout, null)); vf.addView(View.inflate(this, R.layout.noticelayout, null)); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
以上所述是小编给大家介绍的Android仿淘宝头条基于TextView实现上下滚动通知效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章:
相关文章推荐
- Android仿淘宝头条基于TextView实现上下滚动通知效果
- TextView上下滚动实现通知效果
- Android中TextView实现垂直滚动和上下滚动效果
- Android:TextView的垂直滚动效果和上下滚动效果,原生动画实现
- Android:TextView的垂直滚动效果,和上下滚动效果
- Android自定义View实现广告信息上下滚动效果
- Android中TextView实现文字跑马灯效果(滚动轮播)
- 一分钟实现 Android textview 跑马灯文字滚动效果
- android通知公告栏,textview滚动显示上网实现
- Android中TextView实现垂直滚动(轮换效果,非跑马灯)
- Android中使用TextView实现高仿京东淘宝各种倒计时效果
- Android:TextView的垂直滚动效果,和上下滚动效果
- Android基于TextView不获取焦点实现跑马灯效果
- Android TextView实现滚动跑马灯效果Marquee
- android TextView实现实现跑马灯效果,并监听滚动完成动作。
- Android基于TextView属性android:ellipsize实现跑马灯效果的方法
- Android:TextView的垂直滚动效果,和上下滚动效果
- Android 原生控件ViewFlipper实现淘宝头条垂直滚动广告条
- TextSwticher 与 TextView 实现上下滚动和跑马灯效果
- Android TextView实现滚动效果