国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 上下滾動TextSwitcher實例詳解

2019-10-22 18:35:24
字體:
來源:轉載
供稿:網友

Android 上下滾動TextSwitcher實例詳解

1.在activity中需要代碼聲明

textSwitcher = (TextSwitcher)findViewById(R.id.text_switcher);     textSwitcher.setFactory(new ViewFactory() {              @Override       public View makeView() {         TextView tv = new  TextView(MainActivity.this);         tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16.0F);         tv.setTextColor(Color.RED);         return tv;       }     });          textSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.anim_in));     textSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.anim_out)); 

2.兩個anim動畫xml

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"    android:fillAfter="true"    android:shareInterpolator="false"  android:zAdjustment="top">   <translate      android:duration="3000"      android:fromYDelta="100%p"      android:toYDelta="0" /> </set> 
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"   android:fillAfter="true"    android:shareInterpolator="false"  android:zAdjustment="top">       <translate      android:duration="3000"      android:fromYDelta="0"      android:toYDelta="-100%p" />  </set> 
<style name="pop_anim">     <item name="android:windowEnterAnimation">@anim/anim_in</item>   <item name="android:windowExitAnimation">@anim/anim_out</item>   </style> 

3.用線程或者定時器實現循環翻動。

Thread t = new Thread(new Runnable() {          @Override     public void run() {       while (!flag) {         Message msg = new Message();         msg.what = 1;         msg.obj = getItem[i];         handler.sendMessage(msg);         if (i== 2) {           i = 0;         }         try {           t.sleep(3000);           i++;                    } catch (InterruptedException e) {           // TODO Auto-generated catch block           e.printStackTrace();         }       }            } 

4.hanlder更新ui

private Handler handler = new Handler(){     public void handleMessage(android.os.Message msg) {              textSwitcher.setText((String)msg.obj);              super.handleMessage(msg);     };   }; 

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 广灵县| 石棉县| 兴文县| 黄骅市| 江西省| 长宁区| 平舆县| 泽库县| 西吉县| 诸暨市| 德惠市| 聊城市| 五原县| 广灵县| 惠水县| 唐河县| 吉林省| 忻城县| 昭通市| 嘉定区| 安宁市| 汉中市| 麻城市| 都江堰市| 长沙市| 仲巴县| 苏尼特左旗| 宁晋县| 瑞安市| 长岛县| 高淳县| 乌苏市| 云安县| 武胜县| 铜川市| 保定市| 上虞市| 株洲县| 大邑县| 大足县| 六盘水市|