Textview滚动效果
来源:互联网 发布:淘宝搜索指数 编辑:程序博客网 时间:2024/06/05 04:56
项目当中用到了类似淘宝首页淘宝头条的一个效果。这里是通过viewswitcher这个类来实现的.内容部分根基自己的接口提供的数据。
效果图如下:
1.主要代码如下:
import android.app.Activity;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.view.View;import android.view.animation.TranslateAnimation;import android.widget.TextView;import android.widget.ViewSwitcher;import java.util.Timer;import java.util.TimerTask;import cn.com.ethank.mobilehotel.R;public class MainActivity extends Activity { private ViewSwitcher mViewSwitcher; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test); mViewSwitcher = (ViewSwitcher) findViewById(R.id.viewswitcher); mViewSwitcher.setFactory(new ViewSwitcher.ViewFactory() { @Override public View makeView() { return getLayoutInflater().inflate(R.layout.item_viewswitch, null); } }); //设置切入动画 TranslateAnimation animationTop = new TranslateAnimation(0, 0, 200, 0); animationTop.setFillAfter(true); animationTop.setDuration(200); //设置切出动画 TranslateAnimation animationBottom = new TranslateAnimation(0, 0, 0, -200); animationBottom.setFillAfter(true); animationBottom.setDuration(200); mViewSwitcher.setInAnimation(animationTop); mViewSwitcher.setOutAnimation(animationBottom); mTimer.schedule(mTimerTask, 1000, 4000); } Timer mTimer = new Timer(); TimerTask mTimerTask = new TimerTask() { @Override public void run() { mHandler.sendEmptyMessage(0); } }; Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { ((TextView) mViewSwitcher.getNextView().findViewById(R.id.viewswitcher_tv_one)).setText("中包赠送价值200元的套餐"); ((TextView) mViewSwitcher.getNextView().findViewById(R.id.viewswitcher_tv_two)).setText("大包赠送价值500元的套餐"); mViewSwitcher.showNext(); } }; @Override protected void onDestroy() { super.onDestroy(); mHandler.removeCallbacksAndMessages(null); }}
2.布局代码如下(item_viewswitch.xml)
<?xml version="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/viewswitcher_ll" android:layout_width="match_parent" android:layout_height="wrap_content"><TextViewandroid:id="@+id/viewswitcher_tv_one" android:layout_marginTop="9dp" android:singleLine="true" android:layout_width="match_parent" android:textSize="13dp" android:textColor="#474747" android:ellipsize="end" android:layout_height="wrap_content"/><TextViewandroid:layout_marginTop="10dp" android:id="@+id/viewswitcher_tv_two" android:layout_marginBottom="10dp" android:singleLine="true" android:gravity="bottom" android:ellipsize="end" android:textSize="13dp" android:textColor="#474747"android:layout_width="match_parent"android:layout_height="match_parent"/></LinearLayout>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ViewSwitcher android:id="@+id/viewswitcher" android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="none"/></LinearLayout>
链接:http://www.jianshu.com/p/0e4839eff9a4
阅读全文
0 0
- Android TextView滚动效果
- TextView 滚动效果 android
- TextView实现滚动效果
- Android TextView滚动效果
- TextView字体滚动效果
- 设置TextView滚动效果
- Textview滚动效果
- TextView 的ScrollView滚动效果
- Android TextView实现滚动效果
- TextView 的ScrollView滚动效果
- TextView的垂直滚动效果
- Android金钱滚动效果-滚动的textView
- Android:TextView的垂直滚动效果,和上下滚动效果
- Android:TextView的垂直滚动效果,和上下滚动效果
- Android:TextView的垂直滚动效果,和上下滚动效果
- android textview 跑马灯 滚动效果
- android 用textview实现文字滚动效果
- android textview 跑马灯 滚动效果
- 基于Redis实现分布式锁,Redisson使用及源码分析
- 函数参数指针与引用的区别
- 每日一题(17)—— 关键字volatile的作用和三个不同的应用场合
- STM32F4库函数编写modbus协议(转载)
- Bug
- Textview滚动效果
- C++静态库与动态库
- 第2讲:LR自带订票系统脚本说明
- NRF24L01 的双向通信
- Tomact8部署在linux下启动很慢详解
- XUtils3框架的基本使用方法(一)
- 归并排序(演化版by数组)
- 同步/异步与阻塞非阻塞的关系
- 从头到尾打印链表