学习笔记之——使用ViewFlipper实现竖直滚动广告

        功能是上个项目实现的,今天闲来无事就觉得应该把它写成笔记记录下来,写成单独例子,搜集到我自己的功能库中方便以后使用和查阅(其实此功能也是从官方的Demo里面复制代码下来实现的)。感觉自己有点强迫症,一有时间总是想要把自己之前做过项目的一些常用的功能抽离出来保存着以后直接cp,虽然功能很菜   ~O(∩_∩)O哈哈~

        使用ViewFlipper实现滚动广告,效果如下所示:


        首先就是从做着玩玩开始的,实现写死的静态数据的滚动啦~

xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dp"
        android:paddingBottom="5dp">

        <RelativeLayout
            android:id="@+id/relativeLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:background="#f5f5f5" >

            <ViewFlipper
                android:id="@+id/flipper"
                android:layout_width="match_parent"
                android:layout_height="27dp"
                android:flipInterval="2000"
                android:inAnimation="@anim/push_up_in"
                android:outAnimation="@anim/push_up_out" >

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="70dp"
                    android:gravity="center_vertical"
                    android:text="写点评砸金蛋,100%中奖!"
                    android:textColor="#ff0000"
                    android:textSize="16sp" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="70dp"
                    android:ellipsize="end"
                    android:gravity="center_vertical"
                    android:singleLine="true"
                    android:text="央行:九项金融服务国标6月起实施!"
                    android:textColor="#ff0000"
                    android:textSize="16sp" />
            </ViewFlipper>
        </RelativeLayout>

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_centerVertical="true"
            android:src="@drawable/img_hot" />
    </RelativeLayout>

</RelativeLayout>

静态的使用代码非常简单:

ViewFlipper mFlipper = ((ViewFlipper) findViewById(R.id.flipper));
mFlipper.startFlipping();

动画的代码也可以在使用的代码中设置:

mFlipper.setInAnimation(AnimationUtils.loadAnimation(getContext(),R.anim.push_up_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(getContext(),R.anim.push_up_out));

       当然实际项目中还是主要用根据后台服务器返回的数据动态显示啦~

       动态加载就更加简单了,直接加载控件即可

xml:

<ViewFlipper android:id="@+id/flipper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inAnimation="@anim/push_up_in"
        android:outAnimation="@anim/push_up_out"
        android:flipInterval="2000" >
 </ViewFlipper>
使用:

ViewFlipper mFlipper = ((ViewFlipper) heard_four.findViewById(R.id.flipper));
mFlipper.startFlipping();


解析完数据再直接即可啦~

mFlipper.addView(view_adv);


记录完毕~

demo下载:http://download.csdn.net/detail/lxlyhm/9682872
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值