Android自定義FloatingText仿點贊+1特效
本文實例為大家分享了Android自定義View,可以仿點贊往上飄+1的一個特效,或者點擊加入購物車商品拋物線特效。
FloatingText 是一個能夠在任何控件之上執(zhí)行漂浮效果動畫的控件。
原文github地址
效果圖

1. AndroidStudio使用
dependencies {
compile 'com.ufreedom.uikit:FloatingTextLibrary:0.2.0'
}
2. 使用
FloatingText floatingText = new FloatingText.FloatingTextBuilder(Activity)
.textColor(Color.RED) // 漂浮字體的顏色
.textSize(100) // 浮字體的大小
.textContent("+1000") // 浮字體的內(nèi)容
.offsetX(100) // FloatingText 相對其所貼附View的水平位移偏移量
.offsetY(100) // FloatingText 相對其所貼附View的垂直位移偏移量
.floatingAnimatorEffect(FloatingAnimator) // 漂浮動畫
.floatingPathEffect(FloatingPathEffect) // 漂浮的路徑
.build();
floatingText.attach2Window(); //將FloatingText貼附在Window上
//啟動漂浮效果
floatingText.startFloating(View); // 傳入一個View,F(xiàn)loatingText 就會相對于這個View執(zhí)行漂浮效果
自定義漂浮動畫
通過實現(xiàn) FloatingAnimator 接口可以實現(xiàn)自定義漂浮動畫,詳情查看原github。
自定義漂浮路徑
通過實現(xiàn) FloatingPathEffect 和 FloatingPathAnimator 可以自定義路徑動畫
FloatingPath 代表浮動路徑
JAVA
// +1 向上移動效果
final View layoutTranslateFloating = findViewById(R.id.layoutTranslateView);
final View translateFloatingView = findViewById(R.id.translateView);
final FloatingText translateFloatingText = new FloatingText.FloatingTextBuilder(MainActivity.this)
.textColor(Color.RED)
.textSize(100)
.textContent("+1")
.build();
translateFloatingText.attach2Window();
assert layoutTranslateFloating != null;
layoutTranslateFloating.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
translateFloatingText.startFloating(translateFloatingView);
}
});
//+1 放大效果
View layoutScaleView = findViewById(R.id.layoutScaleView);
final View scaleView = findViewById(R.id.scaleView);
final FloatingText scaleFloatingText = new FloatingText.FloatingTextBuilder(MainActivity.this)
.textColor(Color.parseColor("#7ED321"))
.textSize(100)
.offsetY(-100)
.floatingAnimatorEffect(new ScaleFloatingAnimator())
.textContent("+1")
.build();
scaleFloatingText.attach2Window();
assert scaleView != null;
assert layoutScaleView != null;
layoutScaleView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
scaleFloatingText.startFloating(scaleView);
}
});
//自定義 螺旋上升動畫
final FloatingText cubicFloatingText = new FloatingText.FloatingTextBuilder(MainActivity.this)
.textColor(Color.RED)
.textSize(100)
.floatingAnimatorEffect(new CurvePathFloatingAnimator())
.floatingPathEffect(new CurveFloatingPathEffect())
.textContent("Hello! ")
.build();
cubicFloatingText.attach2Window();
View layoutCurveView = findViewById(R.id.layoutCurveView);
final View curveView = findViewById(R.id.curveView);
assert curveView != null;
assert layoutCurveView != null;
layoutCurveView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cubicFloatingText.startFloating(curveView);
}
});
XML
<FrameLayout
android:id="@+id/layoutTranslateView"
android:layout_width="234.4dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
>
<TextView
android:id="@+id/translateView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:text="Translate Floating"
android:textColor="@android:color/white" />
</FrameLayout>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android使用SurfaceView實現(xiàn)飄贊動畫
- Android仿直播特效之點贊飄心效果
- Android貝塞爾曲線實現(xiàn)直播點贊效果
- Android實現(xiàn)朋友圈點贊列表
- Android自定義ViewGroup實現(xiàn)堆疊頭像的點贊Layout
- Android中使用PopupWindow 仿微信點贊和評論彈出
- Android實現(xiàn)點贊動畫(27)
- Android PraiseTextView實現(xiàn)朋友圈點贊功能
- Android listview點贊問題分析
- Android中Listview點贊功能的實現(xiàn)
- 簡單實用的Android UI微博動態(tài)點贊效果
- Android項目開發(fā) 教你實現(xiàn)Periscope點贊效果
- Android控件實現(xiàn)直播App點贊飄心動畫
相關(guān)文章
Android實現(xiàn)仿Windows7圖片預(yù)覽窗格效果
這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)仿Windows7圖片預(yù)覽窗格效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-12-12
解決Android中自定義DialogFragment解決寬度和高度問題
Android中自定義DialogFragment解決寬度和高度問題但是我們很多時候想把DialogFragment的高度固定,那么我們需要設(shè)置DialogFragment的高度,在Fragment的onResume()聲明周期方法中設(shè)置window的寬高即可2017-12-12
Rxjava2_Flowable_Sqlite_Android數(shù)據(jù)庫訪問實例
下面小編就為大家分享一篇Rxjava2_Flowable_Sqlite_Android數(shù)據(jù)庫訪問實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02
詳解Flutter Image組件如何處理圖片加載過程中的錯誤
在Flutter中,Image組件可以通過監(jiān)聽加載過程中的錯誤來處理圖片加載過程中的錯誤,本文小編將給大家詳細(xì)介紹了Flutter Image組件是如何處理圖片加載過程中的錯誤,文中有詳細(xì)的代碼示例供大家參考,需要的朋友可以參下2023-10-10
Android解決getExternalStorageDirectory在29后廢棄問題(推薦)
這篇文章主要介紹了Android解決getExternalStorageDirectory在29后廢棄問題(推薦),本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-02-02

