最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android自定義View實(shí)現(xiàn)廣告信息上下滾動(dòng)效果

 更新時(shí)間:2016年05月27日 10:11:14   作者:pengkv  
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)廣告信息上下滾動(dòng)的具體代碼,感興趣的小伙伴們可以參考一下

先看看效果:

實(shí)現(xiàn)代碼:

public class ScrollBanner extends LinearLayout {

  private TextView mBannerTV1;
  private TextView mBannerTV2;
  private Handler handler;
  private boolean isShow;
  private int startY1, endY1, startY2, endY2;
  private Runnable runnable;
  private List<String> list;
  private int position = 0;
  private int offsetY = 100;


  public ScrollBanner(Context context) {
    this(context, null);
  }

  public ScrollBanner(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
  }

  public ScrollBanner(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    View view = LayoutInflater.from(context).inflate(R.layout.view_scroll_banner, this);
    mBannerTV1 = (TextView) view.findViewById(R.id.tv_banner1);
    mBannerTV2 = (TextView) view.findViewById(R.id.tv_banner2);

    handler = new Handler();

    runnable = new Runnable() {
      @Override
      public void run() {
        isShow = !isShow;

        if (position == list.size())
          position = 0;

        if (isShow) {
          mBannerTV1.setText(list.get(position++));
        } else {
          mBannerTV2.setText(list.get(position++));
        }

        startY1 = isShow ? 0 : offsetY;
        endY1 = isShow ? -offsetY : 0;


        ObjectAnimator.ofFloat(mBannerTV1, "translationY", startY1, endY1).setDuration(300).start();

        startY2 = isShow ? offsetY : 0;
        endY2 = isShow ? 0 : -offsetY;
        ObjectAnimator.ofFloat(mBannerTV2, "translationY", startY2, endY2).setDuration(300).start();

        handler.postDelayed(runnable, 3000);
      }
    };

  }


  public List<String> getList() {
    return list;
  }

  public void setList(List<String> list) {
    this.list = list;
  }

  public void startScroll() {
    handler.post(runnable);
  }

  public void stopScroll() {
    handler.removeCallbacks(runnable);
  }
}

view_scroll_banner.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal"
  android:padding="10dp">

  <TextView
    android:id="@+id/tv_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:text="公告"
    android:textColor="#e76712"
    android:textSize="16sp" />

  <View
    android:id="@+id/view_divider"
    android:layout_width="1dp"
    android:layout_height="match_parent"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_toRightOf="@id/tv_title"
    android:background="#DDDDDD" />

  <TextView
    android:id="@+id/tv_banner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@+id/view_divider"
    android:ellipsize="end"
    android:singleLine="true"
    android:text="熱烈歡迎領(lǐng)導(dǎo)光臨" />

  <TextView
    android:id="@+id/tv_banner2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@+id/view_divider"
    android:ellipsize="end"
    android:singleLine="true"
    android:text="喜慶國(guó)慶歡樂大酬賓" />
</RelativeLayout>

使用方法:

scrollBanner.setList(list);
scrollBanner.startScroll();

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)Android軟件編程有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android ListView的item中嵌套ScrollView的解決辦法

    Android ListView的item中嵌套ScrollView的解決辦法

    有時(shí)候,listview 的item要顯示的字段比較多,考慮到顯示問題,item外面不得不嵌套ScrollView來實(shí)現(xiàn),糾結(jié)怎么解決此問題呢?下面小編給大家分享下Android ListView的item中嵌套ScrollView的解決辦法,感興趣的朋友一起看看吧
    2016-10-10
  • Android SoundPool實(shí)現(xiàn)簡(jiǎn)短小音效

    Android SoundPool實(shí)現(xiàn)簡(jiǎn)短小音效

    這篇文章主要為大家詳細(xì)介紹了Android SoundPool實(shí)現(xiàn)簡(jiǎn)短小音效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • Android實(shí)現(xiàn)屏幕截圖并保存截圖到指定文件

    Android實(shí)現(xiàn)屏幕截圖并保存截圖到指定文件

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)屏幕截圖并保存截取圖片到指定文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • Android提高之XML解析與生成實(shí)例詳解

    Android提高之XML解析與生成實(shí)例詳解

    這篇文章主要介紹了Android的XML解析與生成方法,相信對(duì)大家的Android項(xiàng)目開發(fā)有一定的借鑒參考作用,需要的朋友可以參考下
    2014-08-08
  • 淺談Android面向切面編程(AOP)

    淺談Android面向切面編程(AOP)

    這篇文章主要介紹了淺談Android面向切面編程(AOP),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-11-11
  • Kotlin?協(xié)程的取消機(jī)制詳細(xì)解讀

    Kotlin?協(xié)程的取消機(jī)制詳細(xì)解讀

    這篇文章主要為大家介紹了Kotlin?協(xié)程的取消機(jī)制詳細(xì)解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • Android編程之四種Activity加載模式分析

    Android編程之四種Activity加載模式分析

    這篇文章主要介紹了Android編程之四種Activity加載模式,簡(jiǎn)要分析了Android編程中涉及的Activity的四種加載模式,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2016-01-01
  • Android操作Html打開其他APP

    Android操作Html打開其他APP

    這篇文章主要為大家詳細(xì)介紹了Android操作Html打開其他APP的相關(guān)資料,感興趣的小伙伴們可以參考一下
    2016-08-08
  • Android入門之在子線程中調(diào)用Handler詳解

    Android入門之在子線程中調(diào)用Handler詳解

    這篇文章主要為大家詳細(xì)介紹了Android如何在子線程中調(diào)用Handler,文中的示例代碼講解詳細(xì),有需要的朋友可以借鑒參考下,希望能夠?qū)Υ蠹矣兴鶐椭?/div> 2022-12-12
  • Android獲取應(yīng)用程序大小的方法

    Android獲取應(yīng)用程序大小的方法

    這篇文章主要介紹了Android獲取應(yīng)用程序大小的方法,有需要的朋友可以參考一下
    2014-01-01

最新評(píng)論

阳原县| 周宁县| 曲麻莱县| 长春市| 土默特右旗| 平昌县| 周口市| 柳林县| 朝阳市| 手机| 乐安县| 宜兰市| 宣汉县| 平湖市| 乌苏市| 景谷| 永城市| 汾阳市| 荆州市| 昌乐县| 凭祥市| 阿坝| 溧水县| 沛县| 靖州| 密云县| 凤城市| 牙克石市| 金湖县| 永济市| 宝丰县| 永宁县| 江永县| 定州市| 安顺市| 祁东县| 无锡市| 许昌市| 巨鹿县| 青冈县| 邵东县|