仿淘宝头条的实现[通俗易懂]

仿淘宝头条的实现[通俗易懂]其实很简单,只要用系统提供的控件就可以了,三步轻松搞定!<LinearLayoutxmlns:android="http://s

欢迎大家来到IT世界,在知识的湖畔探索吧!

在淘宝客户端中,有一个垂直轮播的广告条(如下图),这个是怎么显示的呢?其实很简单,只要用系统提供的控件就可以了,三步轻松搞定!

仿淘宝头条的实现[通俗易懂]

image.jpeg

1.设置布局,轮播控件用的是系统的

<?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">
 <ViewFlipper android:id="@+id/vf"
 android:autoStart="true"
 android:flipInterval="5000"
 android:inAnimation="@anim/anim_marquee_in"
 android:outAnimation="@anim/anim_marquee_out"
 android:layout_width="match_parent"
 android:layout_height="100dp"/>
</LinearLayout>

欢迎大家来到IT世界,在知识的湖畔探索吧!

2.设置滚动动画,一个是进入的,一个是出去的

欢迎大家来到IT世界,在知识的湖畔探索吧!<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
 <translate
 android:duration="1500"
 android:fromYDelta="0"
 android:toYDelta="-100%p" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
 <translate
 android:duration="1500"
 android:fromYDelta="100%p"
 android:toYDelta="0"/>
</set>

3.添加View

data.forEachIndexed { index, s ->
 vf.addView(View.inflate(this,R.layout.list_item,null))
 }

4.大功告成,这样你就能在手机中看到类似淘宝的滚动效果,如果滚动速度太慢,还可以通过XML里面的属性进行调整

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://itzsg.com/18223.html

(0)

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

联系我们YX

mu99908888

在线咨询: 微信交谈

邮件:itzsgw@126.com

工作时间:时刻准备着!

关注微信