import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.GestureDetector;
import android.view.View;
import android.widget.ViewFlipper; public class MainActivity extends AppCompatActivity {
ViewFlipper flipper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewFlipper vf = (ViewFlipper) findViewById(R.id.vf);
vf.addView(View.inflate(this, R.layout.guanggao, null));
vf.addView(View.inflate(this, R.layout.guanggao2, null));
vf.addView(View.inflate(this, R.layout.guanggao3, null));
vf.startFlipping();
}
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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.loaderman.viewflipperdemo.MainActivity"> <ViewFlipper
android:id="@+id/vf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoStart="true"
android:flipInterval="3000"
android:inAnimation="@anim/anim_marque_in"
android:outAnimation="@anim/anim_marque_out"
/>
</RelativeLayout>

guanggao.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="match_parent"
android:orientation="vertical"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="热议"
android:textColor="#f00"
android:textSize="18sp"/> <TextView
android:textSize="18sp" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="小米手机降价了"/>
</LinearLayout>
</LinearLayout>

guanggao2.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="match_parent"
android:orientation="vertical"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <TextView
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="#00f"
android:text="爆料"/> <TextView
android:textSize="18sp"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="小米手机降价了"/>
</LinearLayout>
</LinearLayout>

guanggao3.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="match_parent"
android:orientation="vertical"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <TextView
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="#0f0"
android:text="最新"/> <TextView
android:textSize="18sp"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="苹果手机发布了"/>
</LinearLayout>
</LinearLayout>

在res/anim下创建anim_marque_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1500">
<!--anim_marque_in-->
<translate
android:fromYDelta="100%p"
android:toYDelta="0"/>
<alpha
android:duration="300"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>

在res/anim下创建anim_marque_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1500">
<!--anim_marque_out-->
<translate
android:fromYDelta="0%p"
android:toYDelta="-100%p"/>
<alpha
android:duration="300"
android:fromAlpha="1.0"
android:toAlpha="0.0" />
</set>

效果图:

使用ViewFlipper实现广告信息栏的上下翻滚效果的更多相关文章

  1. fiddler工具条、状态栏、请求信息栏各按钮的作用

    1.fiddler工具条 2.fiddler状态栏 3.请求信息栏

  2. Android 通过ViewFlipper实现广告轮播功能并可以通过手势滑动进行广告切换

    为了实现广告轮播功能,在网上找了很多方法,有的效果很好,但是代码太麻烦,并且大多是用的viewpager,总之不是很满意. 于是看了一下sdk有个控件是ViewFlipper,使用比较方便,于是尝试了 ...

  3. 使用ViewFlipper实现广告图片的自动轮播的效果

    轮播资源图片的实现 package com.loaderman.viewflipperdemo; import android.os.Bundle; import android.support.v7 ...

  4. leanote 信息栏显示笔记本和笔记类型

    本文解决如下两个问题: 1. 在列表视图下使用搜索时,不知道搜出来的笔记属于哪个笔记本.(摘要视图下是有显示的) 2. 增加显示笔记类型(markdown 或 富文本) 修改resources\app ...

  5. 自定义有焦点的TextView实现广告信息左右一直滚动的跑马灯效果

    import android.content.Context; import android.text.TextUtils; import android.util.AttributeSet; imp ...

  6. 仿知乎/途家导航栏渐变文字动画效果-b

    demo.gif 效果图如上,简单分析下 1.导航栏一开始是隐藏的,随着scrollView滚动而渐变 2.导航栏左右两边的navigationItem是一直显示的 3.导航栏参考了途家app,使用了 ...

  7. ViewFlipper的简单使用实现图片轮播效果

    /** * ViewFlipper: * 安卓系统自带的一个多页面管理控件,它可以实现子页面的自动切换 * 为ViewFlipper加入View: * (1)在layout布局文件静态导入子View ...

  8. 不可思议的纯CSS导航栏下划线跟随效果

    先上张图,如何使用纯 CSS 制作如下效果? 在继续阅读下文之前,你可以先缓一缓.尝试思考一下上面的效果或者动手尝试一下,不借助 JS ,能否巧妙的实现上述效果. OK,继续.这个效果是我在业务开发的 ...

  9. 奇妙的CSS3—导航栏下划线跟随效果

    先来看一下效果: 1.基本效果就是这样的 ,鼠标悬停,下划线划入.鼠标离开,下划线划出 2.下划线的划入是有方向的,从左侧划入悬停,下划线由左向右伸长.从右侧划入,下划线由又往左伸长 实现思路 1.导 ...

随机推荐

  1. python3.6 错误: ModuleNotFoundError:No module named "Crypto"

    原因及处理:在使用python是经常会用到import一个第三方库,但是有时候会提示某个模块不存在,如Crypto其实是因为Python3里面这个模块的名字变了, pip install pycryp ...

  2. Selenium(4)

    练习1:使用selenium+firefox测试ecshop登录过程 一.WebDriver 1.启动浏览器 (1)启动Firefox浏览器 a.启动默认路径下的浏览器 WebDriver drive ...

  3. libusb_control_setup

     libusb_fill_control_transfer(transfer, devh, buf, ctrl_urb_complete_cb,             utrans, 1000); ...

  4. QT字符串QString

    字符串转数值 --------------------------------------------------------------------------------------------- ...

  5. springboot2.1.7整合Druid

    一.maven的依赖:文中就贴重点的, 其他依赖就不贴了 <dependency> <groupId>com.alibaba</groupId> <artif ...

  6. 二叉树的相关定义及BST的实现

    一.树的一些概念 树,子树,节点,叶子(终端节点),分支节点(分终端节点): 节点的度表示该节点拥有的子树个数,树的度是树内各节点度的最大值: 子节点(孩子),父节点(双亲),兄弟节点,祖先,子孙,堂 ...

  7. JS 函数基础

    函数简介 函数 函数也是一个对象 函数中可以封装一些功能(代码),在需要时可以指向这些功能(代码) 函数中可以保存一些代码在需要时调用 使用typeof检查一个函数对象时,会返回function 创建 ...

  8. Tomcat 调优测试

    测试环境: OS: Ubuntu14.04 64位 (运行在Docker1.9) CPU: Intel i3 双核四线程 Mem: 8G Tomcat版本: Tomcat8.5 Java SDK版本: ...

  9. BZOJ 3594: [Scoi2014]方伯伯的玉米田 (二维树状数组优化DP)

    分析 首先每次增加的区间一定是[i,n][i,n][i,n]的形式.因为如果选择[i,j](j<n)[i,j](j<n)[i,j](j<n)肯定不如把后面的全部一起加111更优. 那 ...

  10. 题解 【NOI2010】超级钢琴

    [NOI2010]超级钢琴 Description 小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的音乐. 这架超级钢琴可以弹奏出n个音符,编号 ...