技術(shù)員聯(lián)盟提供win764位系統(tǒng)下載,win10,win7,xp,裝機(jī)純凈版,64位旗艦版,綠色軟件,免費(fèi)軟件下載基地!

當(dāng)前位置:主頁 > 教程 > 服務(wù)器類 >

Android TextSwitcher如何實(shí)現(xiàn)文字上下翻牌效果

來源:技術(shù)員聯(lián)盟┆發(fā)布時(shí)間:2017-10-08 18:10┆點(diǎn)擊:

tvNotice = (TextSwitcher)rootView.findViewById(R.id.tv_notice); 

tvNotice.setFactory(new ViewSwitcher.ViewFactory() { //這里 用來創(chuàng)建內(nèi)部的視圖,這里創(chuàng)建TextView,用來顯示文字 public View makeView() { TextView tv =new TextView(getContext()); //設(shè)置文字大小 tv.setTextSize(TypedValue.COMPLEX_UNIT_PX,getResources().getDimension(R.dimen.group_notice_font_size)); //設(shè)置文字 顏色 tv.setTextColor(getResources().getColor(R.color.font_333333)); return tv; } });

然后自己可用timer或者Thread去控制輪播,輪播中控制tvNotice的代碼如下

// 設(shè)置切入動(dòng)畫 tvNotice.setInAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.slide_in_bottom)); // 設(shè)置切出動(dòng)畫 tvNotice.setOutAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.slide_out_up)); //items是一個(gè)字符串列表,index就是動(dòng)態(tài)的要顯示的items中的索引 tvNotice.setText(itmes.get(index).getTitle());

slide_in_bottom.xml

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="" android:fillAfter="true" android:shareInterpolator="false" android:zAdjustment="top" > <translate android:duration="1000" android:fromYDelta="100%p" android:toYDelta="0" /> </set>

slide_out_up.xml

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="" android:fillAfter="true" android:shareInterpolator="false" android:zAdjustment="top" > <translate android:duration="1000" android:fromYDelta="0" android:toYDelta="-100%p" /> </set>