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

Android自定義TextBanner實(shí)現(xiàn)自動(dòng)滾動(dòng)

 更新時(shí)間:2020年07月23日 16:16:38   作者:空山新雨后來(lái)秋  
這篇文章主要為大家詳細(xì)介紹了Android自定義TextBanner實(shí)現(xiàn)自動(dòng)滾動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android自定義TextBanner實(shí)現(xiàn)自動(dòng)滾動(dòng)的具體代碼,供大家參考,具體內(nèi)容如下

1、TextBanner

package com.example.myapplication.customview;
 
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.ViewFlipper;
 
import com.example.myapplication.R;
 
import java.util.ArrayList;
import java.util.List;
 
public class TextBanner extends ViewGroup {
 private List<String> mData = new ArrayList<>();
 private ViewFlipper viewFlipper;
 private int parentWidthSpec;
 
 public TextBanner(Context context) {
 super(context);
 }
 
 public TextBanner(Context context, AttributeSet attrs) {
 super(context, attrs);
 }
 
 public TextBanner(Context context, AttributeSet attrs, int defStyleAttr) {
 super(context, attrs, defStyleAttr);
 }
 
 @Override
 protected void onLayout(boolean changed, int l, int t, int r, int b) {
 
 
 int top = 0;
 int bottom = getChildAt(0).getMeasuredHeight();
 
 
 int left = 0;
 for (int i = 0; i < getChildCount(); i++) {
  View view = getChildAt(i);
  left = (parentWidthSpec - view.getMeasuredWidth()) / 2;
  view.layout(left, top, left + view.getMeasuredWidth(), bottom);
  top += view.getMeasuredHeight();
  bottom = top + view.getMeasuredHeight();
 
 }
 Log.d("tzg", "bottom: " + bottom);
 Log.d("tzg", "top: " + top);
 
 
 }
 
 
 public void setData(List<String> data) {
 mData.clear();
 if (data.isEmpty()) {
  return;
 }
 this.mData = data;
 
 setTextList();
 }
 
 private void setTextList() {
 viewFlipper = (ViewFlipper) LayoutInflater.from(getContext()).inflate(R.layout.flow_layout_viewflip, this, false);
 for (String mDatum : mData) {
 
  TextView view = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.flow_layout_textview, this, false);
  view.setText(mDatum);
  viewFlipper.addView(view);
 
 }
 viewFlipper.setInAnimation(getContext(), R.anim.come_in);
 viewFlipper.setOutAnimation(getContext(), R.anim.come_out);
 viewFlipper.setFlipInterval(2000);
 addView(viewFlipper);
 }
 
 
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 
 parentWidthSpec = MeasureSpec.getSize(widthMeasureSpec);
 int parentHeightSpec = MeasureSpec.getSize(heightMeasureSpec);
 
 
 int childWidth = MeasureSpec.makeMeasureSpec(parentWidthSpec, MeasureSpec.AT_MOST);
 int childHeight = MeasureSpec.makeMeasureSpec(parentHeightSpec, MeasureSpec.AT_MOST);
 
 int totalHeight = getChildAt(0).getMeasuredHeight();
 
 for (int i = 0; i < getChildCount(); i++) {
  View view = getChildAt(i);
  measureChild(view, childWidth, childHeight);
 }
 Log.d("tzg", "totalCount: " + totalHeight);
 setMeasuredDimension(parentWidthSpec, totalHeight);
 
 }
 
 
 public void startAnimation() {
 // 1、設(shè)置幻燈片的形式滾動(dòng)
 // viewFlipper.startFlipping();
 
 // 2、設(shè)置自動(dòng)翻頁(yè)滾動(dòng)
 viewFlipper.setAutoStart(true);
 viewFlipper.isAutoStart();
 }
}

用到的資源 

1、動(dòng)畫(huà)資源

(1)、come_in.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
 
 <translate
 android:duration="1000"
 android:fromYDelta="100%p"
 android:toYDelta="0"/>
 
</set>

(2)、come_out.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
 
 <translate
 android:duration="1000"
 android:fromYDelta="0"
 android:toYDelta="-100%p"/>
 
</set>

2、布局資源

(1)、flow_layout_viewflip.xml

<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_gravity="center">
</ViewFlipper>

(2)、flow_layout_textview.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:gravity="center"
 android:padding="5dp"
 android:text="demo"
 android:textColor="#FF00FF" />

3、在mainActivity中的使用

package com.example.myapplication;
 
import androidx.appcompat.app.AppCompatActivity;
 
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
 
import com.example.myapplication.customview.FlowLayout;
import com.example.myapplication.customview.TextBanner;
 
import java.util.ArrayList;
 
public class MainActivity extends AppCompatActivity {
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 ArrayList<String> arrayList = new ArrayList<>();
 arrayList.add("111111111");
 arrayList.add("222222222222444444444444");
 arrayList.add("你好5");
 arrayList.add("你好633");
 arrayList.add("你好a7好a7");
 arrayList.add("你好7889");
 arrayList.add("你好2323423423 ");
 arrayList.add("你好sdfsfada你好sdfsfada ");
 arrayList.add("你好34345");
 arrayList.add("pppppppp");
 arrayList.add("你好");
 arrayList.add("你好你好");
 arrayList.add("電視");
 arrayList.add("冰箱冰箱冰箱冰箱冰箱冰箱冰箱冰箱冰箱冰箱");
 arrayList.add("woaoni");
 arrayList.add("你好");
 arrayList.add("你好");
 TextBanner viewById = this.findViewById(R.id.text_banner);
 viewById.setData(arrayList);
 viewById.startAnimation();
 }
}

具體效果

沒(méi)有自測(cè)哦  有bug自己解決

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

相關(guān)文章

  • Android DrawableTextView圖片文字居中顯示實(shí)例

    Android DrawableTextView圖片文字居中顯示實(shí)例

    在我們開(kāi)發(fā)中,TextView設(shè)置Android:drawableLeft一定使用的非常多,但Drawable和Text同時(shí)居中顯示可能不好控制,小編想到通過(guò)自定義TextView實(shí)現(xiàn),具體詳情大家參考下本文
    2017-03-03
  • Android網(wǎng)絡(luò)判斷知識(shí)小結(jié)

    Android網(wǎng)絡(luò)判斷知識(shí)小結(jié)

    本文通過(guò)兩段實(shí)例代碼分別給大家介紹Android中判斷當(dāng)前網(wǎng)絡(luò)是否可用和Android 關(guān)于判斷應(yīng)用是否有網(wǎng)絡(luò)的相關(guān)知識(shí),對(duì)android網(wǎng)絡(luò)判斷相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧
    2015-12-12
  • Android-AnsyncTask異步任務(wù)的使用

    Android-AnsyncTask異步任務(wù)的使用

    本篇文章主要介紹了Android-AnsyncTask異步任務(wù)的使用,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-01-01
  • Android編程之內(nèi)存溢出解決方案(OOM)實(shí)例總結(jié)

    Android編程之內(nèi)存溢出解決方案(OOM)實(shí)例總結(jié)

    這篇文章主要介紹了Android編程之內(nèi)存溢出解決方案(OOM),結(jié)合實(shí)例實(shí)例總結(jié)分析了Android編程過(guò)程中常見(jiàn)的內(nèi)存溢出情況與對(duì)應(yīng)的解決方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-11-11
  • Flutter路由框架Fluro使用簡(jiǎn)介

    Flutter路由框架Fluro使用簡(jiǎn)介

    這篇文章主要介紹了Flutter路由框架Fluro使用簡(jiǎn)介,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • Android實(shí)現(xiàn)計(jì)步進(jìn)度的環(huán)形Progress

    Android實(shí)現(xiàn)計(jì)步進(jìn)度的環(huán)形Progress

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)計(jì)步進(jìn)度的環(huán)形Progress,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android 監(jiān)聽(tīng)軟鍵盤(pán)狀態(tài)的實(shí)例詳解

    Android 監(jiān)聽(tīng)軟鍵盤(pán)狀態(tài)的實(shí)例詳解

    這篇文章主要介紹了Android 監(jiān)聽(tīng)軟鍵盤(pán)狀態(tài)的實(shí)例詳解的相關(guān)資料,希望通過(guò)本文能掌握這樣的知識(shí),需要的朋友可以參考下
    2017-09-09
  • android的RecyclerView實(shí)現(xiàn)拖拽排序和側(cè)滑刪除示例

    android的RecyclerView實(shí)現(xiàn)拖拽排序和側(cè)滑刪除示例

    在平時(shí)開(kāi)發(fā)應(yīng)用的時(shí)候,經(jīng)常會(huì)遇到列表排序、滑動(dòng)刪除的需求。這篇文章主要介紹了android的RecyclerView實(shí)現(xiàn)拖拽排序和側(cè)滑刪除示例,有興趣的可以了解一下。
    2017-02-02
  • android實(shí)現(xiàn)通過(guò)NFC讀取卡號(hào)

    android實(shí)現(xiàn)通過(guò)NFC讀取卡號(hào)

    這篇文章主要介紹了android實(shí)現(xiàn)通過(guò)NFC讀取卡號(hào),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Android studio自定義對(duì)話框效果

    Android studio自定義對(duì)話框效果

    這篇文章主要為大家詳細(xì)介紹了Android studio自定義對(duì)話框效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10

最新評(píng)論

大新县| 内丘县| 喜德县| 田林县| 山阴县| 灌阳县| 惠东县| 广东省| 麟游县| 仪陇县| 茶陵县| 卓资县| 十堰市| 黄浦区| 土默特右旗| 黄梅县| 固镇县| 霍林郭勒市| 吴桥县| 乐山市| 平泉县| 当雄县| 封丘县| 梁河县| 平罗县| 望江县| 正安县| 阿勒泰市| 阿克苏市| 湖北省| 江阴市| 双柏县| 延寿县| 锡林浩特市| 甘泉县| 黔西| 二手房| 青岛市| 商洛市| 吐鲁番市| 纳雍县|