Android ViewFlipper的使用(上下滚动)
作者:互联网
Android ViewFlipper的使用(上下滚动)
private ViewFlipper mUPMarqueeView; //初始化
mUPMarqueeView =findViewById(R.id.view_flipper);
1, 在layout添加
<ViewFlipper
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/view_flipper"
android:flipInterval="2500"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:layout_marginEnd="5dp"
android:inAnimation="@anim/anim_marquee_in"
android:outAnimation="@anim/anim_marquee_out"
/>
2,创建anim
anim_marquee_in
<translate android:duration="800" android:fromYDelta="100%p" android:toYDelta="0"/>
anim_marquee_out
<translate android:duration="800" android:fromYDelta="0" android:toYDelta="-100%p"/>
3,动态添加布局
for (int i = 0; i < bannerdata.size(); i = i + 2) {
//设置滚动的单个布局
LinearLayout moreView = (LinearLayout)
LayoutInflater.from(this).inflate (R.layout.item_headline_advertisement, null);
//初始化布局的控件
TextView mTvTitle1 = moreView.findViewById(R.id.first_headline_content);
TextView mTvTitle2 = moreView.findViewById(R.id.second_headline_content);
//进行对控件赋值
mTvTitle1.setText(bannerdata.get(i));
//添加到循环滚动数组里面去
mUPMarqueeView.addView(moreView);
}
mUPMarqueeView.startFlipping();
标签:findViewById,滚动,headline,moreView,ViewFlipper,mUPMarqueeView,Android,id 来源: https://blog.csdn.net/qq_28189091/article/details/114635308