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

Android TextSwitcher文本切換器和ViewFlipper使用詳解

 更新時(shí)間:2017年06月20日 11:48:52   作者:ganchuanpu  
這篇文章主要為大家詳細(xì)介紹了Android TextSwitcher文本切換器和ViewFlipper的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文為大家分享了Android TextSwitcher文本切換器的使用,供大家參考,具體內(nèi)容如下

1.TextSwitcher

 使用:

應(yīng)用分為三步:

1.得到 TextSwitcher 實(shí)例對(duì)象
  TextSwitcher switcher = (TextSwitcher) findViewById(R.id.textSwitcher);
2.為switcher指定ViewSwitcher.ViewFactory工廠,該工廠會(huì)產(chǎn)生出轉(zhuǎn)換時(shí)需要的View
  switcher.setFactory(this);
3.為switcher設(shè)定顯示的內(nèi)容,該方法執(zhí)行,就會(huì)切換到下個(gè)View
  switcher.setText(String.valueOf(new Random().nextInt()));

2.ViewFlipper

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

①創(chuàng)建主布局文件,包含ViewFlipper控件(從源碼來看,ViewFlipper控件是集成FrameLayout,也是相當(dāng)于一個(gè)幀布局,只是包含了一些特殊的屬性)

②創(chuàng)建ViewFlipper的子View,就是兩個(gè)LinearLayout(里面包含兩個(gè)TextView)

③創(chuàng)建ViewFlipper中子view的進(jìn)入和退出動(dòng)畫anim_in和anim_out兩個(gè)動(dòng)畫文件

④在Activity中將兩個(gè)子View添加到ViewFlipper中去,調(diào)動(dòng)的是ViewFlipper的addView方法

具體代碼:

①創(chuàng)建主布局文件

 activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fitsSystemWindows="true"
  tools:context="com.qianmo.rollads.MainActivity">
 
  <android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">
 
    <android.support.v7.widget.Toolbar
      android:id="@+id/toolbar"
      android:layout_width="match_parent"
      android:layout_height="?attr/actionBarSize"
      android:background="?attr/colorPrimary"
      app:popupTheme="@style/AppTheme.PopupOverlay"/>
 
  </android.support.design.widget.AppBarLayout>
 
  <RelativeLayout
    android:id="@+id/content_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.qianmo.rollads.MainActivity"
    tools:showIn="@layout/activity_main">
 
    <ViewFlipper
      android:id="@+id/viewFlipper"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:autoStart="true"
      android:background="#fff"
      android:flipInterval="3000"
      android:inAnimation="@anim/anim_in"
      android:outAnimation="@anim/anim_out"
      android:paddingLeft="30dp"
      >
    </ViewFlipper>
  </RelativeLayout>
  <android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@android:drawable/ic_dialog_email"/>
 
</android.support.design.widget.CoordinatorLayout>

②創(chuàng)建ViewFlipper的子View,這里有兩個(gè),我就只給出一個(gè)來了,另一個(gè)是一樣的

one_ads.xml

<?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="match_parent"
       android:orientation="vertical"
       android:padding="8dp"
  >
 
  <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    >
 
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="熱議"
      android:textColor="#F14C00"
      android:textSize="12sp"
      android:background="@drawable/bg"
      />
 
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:ellipsize="end"
      android:padding="3dp"
      android:singleLine="true"
      android:text="小米8問世,雷胖子現(xiàn)在笑的開心了啦!"
      android:textColor="#333"
      android:textSize="16sp"
      />
 
  </LinearLayout>
 
  <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    >
 
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="熱議"
      android:textColor="#F14C00"
      android:textSize="12sp"
      android:background="@drawable/bg"
      />
 
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:ellipsize="end"
      android:padding="3dp"
      android:singleLine="true"
      android:text="取了個(gè)漂亮的媳婦,整的是好開心!"
      android:textColor="#333"
      android:textSize="16sp"
      />
 
  </LinearLayout>
 
</LinearLayout>

③創(chuàng)建ViewFlipper中子view的進(jìn)入和退出動(dòng)畫anim_in和anim_out兩個(gè)動(dòng)畫文件,這里也只給出anim_in的代碼,anim_out代碼是類似的

anim_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
  <translate
    android:duration="1500"
    android:fromYDelta="100%p"
    android:toYDelta="0"
    />
</set>

④在Activity中將兩個(gè)子View添加到ViewFlipper中去,調(diào)動(dòng)的是ViewFlipper的addView方法

  MainActivity.java

package com.qianmo.rollads;
 
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ViewFlipper;
 
public class MainActivity extends AppCompatActivity {
 
  private ViewFlipper viewFlipper;
 
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper);
    setSupportActionBar(toolbar);
 
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
            .setAction("Action", null).show();
      }
    });
 
    viewFlipper.addView(View.inflate(this, R.layout.one_ads, null));
    viewFlipper.addView(View.inflate(this, R.layout.two_ads, null));
  }
 
} 

ok,來看一下我們的效果

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

相關(guān)文章

  • Android實(shí)現(xiàn)圓形圖片或者圓角圖片

    Android實(shí)現(xiàn)圓形圖片或者圓角圖片

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)圓形圖片或者圓角圖片的代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • 分享一個(gè)Android設(shè)置圓形圖片的特別方法

    分享一個(gè)Android設(shè)置圓形圖片的特別方法

    圓形圖片想必是項(xiàng)目開發(fā)中也是不少用的一個(gè)知識(shí)點(diǎn)吧。那么這里學(xué)習(xí)一下簡(jiǎn)單的制作圓形圖片,這個(gè)方法不用于平時(shí)的實(shí)現(xiàn)方法,有需要的可以參考借鑒。
    2016-09-09
  • Android WebView上實(shí)現(xiàn)JavaScript與Java交互

    Android WebView上實(shí)現(xiàn)JavaScript與Java交互

    這篇文章主要介紹了Android WebView上實(shí)現(xiàn)JavaScript與Java交互 的相關(guān)資料,需要的朋友可以參考下
    2016-03-03
  • 詳解Android的反編譯和代碼混淆

    詳解Android的反編譯和代碼混淆

    本篇文章主要介紹了詳解Android的反編譯和代碼混淆,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-11-11
  • 詳解Android如何實(shí)現(xiàn)自定義的動(dòng)畫曲線

    詳解Android如何實(shí)現(xiàn)自定義的動(dòng)畫曲線

    最近在寫動(dòng)畫相關(guān)的篇章,經(jīng)常會(huì)用到 Curve 這個(gè)動(dòng)畫曲線類,那這個(gè)類到底怎么實(shí)現(xiàn)的?如果想自己來一個(gè)自定義的動(dòng)畫曲線該怎么弄?本文將為大家詳細(xì)解答
    2022-04-04
  • Android10 App啟動(dòng)Activity源碼分析

    Android10 App啟動(dòng)Activity源碼分析

    這篇文章主要為大家介紹了Android10 App啟動(dòng)Activity源碼分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • 使用Android自定義控件實(shí)現(xiàn)滑動(dòng)解鎖九宮格

    使用Android自定義控件實(shí)現(xiàn)滑動(dòng)解鎖九宮格

    最近由于Android項(xiàng)目需要,要求做一個(gè)類似于支付寶的九宮格解鎖組件,下面小編給大家分享了具體實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2015-10-10
  • Android開發(fā)中Launcher3常見默認(rèn)配置修改方法總結(jié)

    Android開發(fā)中Launcher3常見默認(rèn)配置修改方法總結(jié)

    這篇文章主要介紹了Android開發(fā)中Launcher3常見默認(rèn)配置修改方法,結(jié)合實(shí)例形式分析了Android Launcher3的功能與配置修改相關(guān)操作技巧,需要的朋友可以參考下
    2017-11-11
  • Android判斷json格式將錯(cuò)誤信息提交給服務(wù)器

    Android判斷json格式將錯(cuò)誤信息提交給服務(wù)器

    今天小編就為大家分享一篇關(guān)于Android判斷json格式將錯(cuò)誤信息提交給服務(wù)器,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • 解決Android studio模擬器啟動(dòng)失敗的問題

    解決Android studio模擬器啟動(dòng)失敗的問題

    這篇文章主要介紹了Android studio模擬器啟動(dòng)失敗的問題及解決方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-03-03

最新評(píng)論

宝应县| 蓬莱市| 汝南县| 咸阳市| 锡林郭勒盟| 商南县| 龙江县| 镇沅| 当涂县| 昭平县| 三江| 连云港市| 陵川县| 灵石县| 霍州市| 砚山县| 成安县| 保德县| 柞水县| 柘荣县| 马边| 安平县| 仁化县| 定州市| 交口县| 丹江口市| 噶尔县| 东兰县| 清苑县| 五莲县| 南通市| 绥中县| 正定县| 日喀则市| 安顺市| 海门市| 蓬莱市| 平果县| 龙海市| 抚州市| 喜德县|