跑马灯简单实现

如果没有接口调取内容需要在布局中添加内容以及动画

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="60dp">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="50dp"
       android:layout_marginLeft="20dp"
        android:background="@drawable/qqq"
        android:gravity="center">

        <TextView
            android:textSize="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="京东" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="20dp"
            android:src="@drawable/kuaibao" />

        <ViewFlipper
            android:id="@+id/view_flipper"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:flipInterval="2000">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <TextView
                    android:textSize="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="爆"
                    android:textColor="#FF0000" />

                <TextView
                    android:textSize="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="荣耀 V10竟然这么快!" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <TextView
                    android:textSize="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="热门"
                    android:textColor="#FF0000" />

                <TextView
                    android:textSize="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="这群变态,直接把球鞋放在嘴里" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:textSize="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="深夜发媸:最小题大做的美妆" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:textSize="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="HOT"
                    android:textColor="#FF0000" />

                <TextView
                    android:textSize="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="戴上这副骚耳机,Beats都哭了" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:textSize="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="HOT"
                    android:textColor="#FF0000" />

                <TextView
                    android:textSize="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="上千的耐克鞋拆开是啥样?" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:textSize="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="爆"
                    android:textColor="#FF0000" />

                <TextView
                    android:textSize="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="打呼噜竟然和枕头有关?" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:textSize="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="推荐"
                    android:textColor="#FF0000" />

                <TextView
                    android:textSize="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="福特复仇法拉利?50年不死不休" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:textSize="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="推荐"
                    android:textColor="#FF0000" />

                <TextView
                    android:textSize="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="余文乐,行走的潮流教科书" />

            </LinearLayout>

        </ViewFlipper>

        <TextView
            android:textSize="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="|" />

        <TextView
            android:textSize="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="20dp"
            android:text="更多" />

    </LinearLayout>

</RelativeLayout>
 
//动画---anim中设置两个动画-push_up_in
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

    <translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="300"/>
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />
</set>
 
----push_up_out
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromYDelta="0" android:toYDelta="-100%p" android:duration="300"/>
    <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="300" />
</set>
 
在Antivity中获取控件进行适配就可以实现简单的文字转换跑马灯
 
pu = view.findViewById(R.id.pubu);
//跑马灯适配
viewFlipper.startFlipping();
 
 
 
 
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值