怎么在Android使用ViewFlipper實(shí)現(xiàn)一個(gè)上下滾動(dòng)消息

這篇文章將為大家詳細(xì)講解有關(guān)怎么在Android使用ViewFlipper實(shí)現(xiàn)一個(gè)上下滾動(dòng)消息,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。

成都創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),姜堰企業(yè)網(wǎng)站建設(shè),姜堰品牌網(wǎng)站建設(shè),網(wǎng)站定制,姜堰網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,姜堰網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。

1.在界面布局中加入ViewFlipper的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/ll_notice_root"
       android:layout_width="match_parent"
       android:layout_height="40dp"
       android:background="#ffe4c3"
       android:gravity="center_vertical"
       android:orientation="horizontal">
 
  <ViewFlipper
    android:id="@+id/vf_notice_scroll"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"/>
 
</LinearLayout>

2.創(chuàng)建需要滾動(dòng)的子布局notice_item文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:gravity="center_vertical"
       android:orientation="horizontal">
 
  <TextView
    android:id="@+id/tv_notice_item_itle"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_weight="1"
    android:text="標(biāo)題"
    android:textColor="#9B6916"
    android:textSize="12dp"/>
 
  <TextView
    android:id="@+id/tv_notice_item_time"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:text="06:28"
    android:textColor="#999999"
    android:textSize="12dp"/>
</LinearLayout>

3.創(chuàng)建平移、漸變動(dòng)畫(huà)文件

(1)進(jìn)場(chǎng)動(dòng)畫(huà)notice_in文件

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
 
  <translate
    android:duration="500"
    android:fromYDelta="100.0%p"
    android:toYDelta="0.0"/>
 
  <alpha
    android:duration="500"
    android:fromAlpha="0.0"
    android:toAlpha="1.0"/>
 
</set>

(2)離場(chǎng)動(dòng)畫(huà)notice_out文件

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
 
  <translate
    android:duration="500"
    android:fromYDelta="0.0"
    android:toYDelta="-100.0%p"/>
 
  <alpha
    android:duration="500"
    android:fromAlpha="1.0"
    android:toAlpha="0.0"/>
 
</set>

4.在Activity中將子布局加入列表中,實(shí)現(xiàn)上下滾動(dòng)效果

public void startFlipping(Context context, ViewFlipper vf, ArrayList<MessageBean> infos){
    vf.setInAnimation(context, R.anim.notice_in);
    vf.setOutAnimation(context, R.anim.notice_out);
    int len = infos.size();
    for (int i = 0; i < len; i++) {
      MessageBean info = infos.get(i);
      View v = ((Activity) context).getLayoutInflater().inflate(R.layout.notice_item, null);
      TextView titleTv = (TextView) v.findViewById(R.id.tv_notice_item_title);
      titleTv.setText(info.title);
      TextView timeTv = (TextView) v.findViewById(R.id.tv_notice_item_time);
      timeTv.setText(info.time);
      vf.addView(v);
    }
    vf.startFlipping();
}

關(guān)于怎么在Android使用ViewFlipper實(shí)現(xiàn)一個(gè)上下滾動(dòng)消息就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。

分享標(biāo)題:怎么在Android使用ViewFlipper實(shí)現(xiàn)一個(gè)上下滾動(dòng)消息
鏈接地址:http://muchs.cn/article40/jioieo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)企業(yè)網(wǎng)站制作、網(wǎng)站策劃、虛擬主機(jī)、自適應(yīng)網(wǎng)站、網(wǎng)站營(yíng)銷

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作