TextView上下滚动实现通知效果
来源:互联网 发布:java 抽象工厂类 编辑:程序博客网 时间:2024/05/19 22:49
最近有个项目需要实现通知栏的上下滚动效果,仿淘宝头条的那种。
我从网上看了一些代码,把完整的效果做了出来。如图所示:
具体代码片段如下:
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"><translateandroid: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 {@Overrideprotected 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));}@Overridepublic 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;}}完整的项目代码可以到http://download.csdn.net/detail/qq_36135928/9774548此处下载。
(我在Android的道路上越走越远。。。)
5 0
- TextView上下滚动实现通知效果
- Android仿淘宝头条基于TextView实现上下滚动通知效果
- TextSwticher 与 TextView 实现上下滚动和跑马灯效果
- 实现上下滚动的TextView
- 实现上下滚动的TextView
- 实现上下滚动的TextView
- Android:TextView的垂直滚动效果和上下滚动效果,原生动画实现
- TextView实现滚动效果
- Android:TextView的垂直滚动效果,和上下滚动效果
- Android:TextView的垂直滚动效果,和上下滚动效果
- Android:TextView的垂直滚动效果,和上下滚动效果
- 实现TextView文本的上下滚动
- ViewFilpper实现多个TextView上下滚动
- Android TextView实现滚动效果
- 首页通知上下翻滚效果的实现
- android textView 上下滚动
- JS实现文本内容上下滚动效果
- js实现文字定时上下滚动效果
- android Comparator做排序
- HDU problem 5635 LCP Array【思维】
- linux 静态库与共享库
- LVS_NAT模式
- 【latin】mysql校对规则(COLLATION)详解
- TextView上下滚动实现通知效果
- 你真的了解一段Java程序的生命史吗?
- Unity中Button的颜色如何用脚本改变
- RabbitMQ 持久化
- 关闭Eclipse按空格和等号键自动补全内容
- openwrt 添加应用程序自启动
- HashMap,Hashtable以及ConcurrentHashMap的比较(源码)
- C++ 基础(二) —— 变量与基本类型
- [LeetCode] 26. Remove Duplicates from Sorted Array java