Android 原生控件ViewFlipper实现淘宝头条垂直滚动广告条

  • showNext():                 显示ViewFlipper里的下一个View

  • showPrevious():          显示ViewFlipper里的上一个View

四、ViewFlipper的详细使用设置View

1.首先在xml中声明ViewFlipper

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“100dp”

android:orientation=“horizontal”>

<ImageView

android:layout_width=“0dp”

android:layout_height=“60dp”

android:layout_weight=“1”

android:src=“@mipmap/toutiao”/>

<View

android:layout_width=“1dp”

android:layout_height=“60dp”

android:background=“#b6b5b5”

android:layout_marginLeft=“5dp”

android:layout_marginRight=“5dp”/>

<ViewFlipper

android:id=“@+id/view_flipper”

android:layout_width=“0dp”

android:layout_weight=“4”

android:layout_height=“60dp”

android:autoStart=“true”

android:flipInterval=“3000”

android:inAnimation=“@anim/flipper_in_anim”

android:outAnimation=“@anim/flipper_out_anim”/>

2.在res下创建anim文件夹,并在里面创建两个xml分别是入场动画和出场动画

<translate xmlns:android=“http://schemas.android.com/apk/res/android”

android:fromYDelta=“100%p”

android:toYDelta=“0”

android:duration=“1500”>

<translate xmlns:android=“http://schemas.android.com/apk/res/android”

android:fromYDelta=“0”

android:toYDelta=“-100%p”

android:duration=“1500”>

3.在java代码中初始化ViewFlipper,并添加子
布局(在这里我们只显示了一个子布局)

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:orientation=“vertical” android:layout_width=“match_parent”

android:layout_height=“match_parent”>

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”

android:orientation=“horizontal”>

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=" 运动 "

android:textColor=“#ff0000”

android:background=“@drawable/text_shap”/>

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=" 精致!哈登上脚 Harden 1"/>

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1”

android:orientation=“horizontal”>

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=" 热品 "

android:textColor=“#ff0000”

android:background=“@drawable/text_shap”/>

<TextView

android:layout_width=“wrap_content”

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值