前言
每過一段時間呀,我都會給大家帶來一些從Github上收集的一些開源庫,有的是炫酷動效,有的則是實用的工具和類庫。2020年有哪些優秀的開源庫呢?本期就爲大家帶精選的10個,排名不分先後。
No1. LiquidSwipe
這是一個很棒的ViewPager庫,它在瀏覽ViewPager的不同頁面時,顯示波浪的滑動動畫,效果非常炫酷。該庫的USP是觸摸交互的。這意味着在視圖中顯示類似液體的顯示過渡時,應考慮觸摸事件。
1.1如何使用呢?
導入以下Gradle依賴項:
implementation 'com.github.Chrisvin:LiquidSwipe:1.3'
然後將LiquidSwipeLayout添加爲保存fragment佈局的容器的根佈局:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.jem.liquidswipe.LiquidSwipeViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
1.2 效果圖
我的學習Android進階之路
接下來,爲大家介紹下我學習Android時用到的一些資料與視頻,需要的夥伴可以
私信我【進階】,我分享給你,也是感謝大家這麼久以來對我的支持。
330頁Android進階核心筆記
B站Android進階視頻
去B站搜索,B站賬號:bili_84936792704 即可觀看哦!
OK,廢話不多說接下來繼續看文章吧。
No2. Flourish
Flourish提供了一個炫酷的方式來顯示或者隱藏一個佈局,實現方式也很簡單,就是對View或者佈局進行了包裝,通過構建者模式來提供api給上層調用。就像使用dialog一樣,調用show和dissmiss方法來顯示和隱藏。此外,通過這些類,我們還可以自定義動畫(正常,加速,反彈),或爲佈局方向設置我們自己的起點(左上,右下等)。
2.1 如何使用?
在build.gradle 中添加如下依賴:
dependencies {
implementation "com.github.skydoves:flourish:1.0.0"
}
然後在代碼中,構建佈局:
Flourish flourish = new Flourish.Builder(parentLayout)
// sets the flourish layout for showing and dismissing on the parent layout.
.setFlourishLayout(R.layout.layout_flourish_main)
// sets the flourishing animation for showing and dismissing.
.setFlourishAnimation(FlourishAnimation.BOUNCE)
// sets the orientation of the starting point.
.setFlourishOrientation(FlourishOrientation.TOP_LEFT)
// sets a flourishListener for listening changes.
.setFlourishListener(flourishListener)
// sets the flourish layout should be showed on start.
.setIsShowedOnStart(false)
// sets the duration of the flourishing.
.setDuration(800L)
.build();
還提供有更簡潔的DSL:
val myFlourish = createFlourish(parentLayout) {
setFlourishLayout(R.layout.layout_flourish_main)
setFlourishAnimation(FlourishAnimation.ACCELERATE)
setFlourishOrientation(FlourishOrientation.TOP_RIGHT)
setIsShowedOnStart(true)
setFlourishListener { }
}
2.2 效果圖
更多詳細使用請看Github:https://github.com/skydoves/Flourish
No3. AestheticDialogs
這是一個美觀而時尚的AlterDialog庫,目前可支持六種不同的對話框,如:
- Flash Dialog
- Connectify Dialog
- Toaster Dialog
- Emotion Dialog
- Drake Dialog
- Emoji Dialog並且啊,還提供了暗黑模式的適配。
3.1 如何使用?
在build.gradle 中添加如下依賴:
dependencies {
...
implementation 'com.github.gabriel-TheCode:AestheticDialogs:1.1.0'
}
代碼中,顯示不同種類的對話框則調用對應的方法就好
Flash:
AestheticDialog.showFlashDialog(this, "Your dialog Title", "Your message", AestheticDialog.SUCCESS);
AestheticDialog.showFlashDialog(this, "Your dialog Title", "Your message", AestheticDialog.ERROR);
Connectify:
AestheticDialog.showConnectify(this,"Your message", AestheticDialog.SUCCESS);
AestheticDialog.showConnectify(this, "Your message", AestheticDialog.ERROR);
/// Dark Theme
AestheticDialog.showConnectifyDark(this,"Your message",AestheticDialog.SUCCESS);
AestheticDialog.showConnectifyDark(this, "Your message", AestheticDialog.ERROR);
Toaster:
AestheticDialog.showToaster(this, "Your dialog Title", "Your message", AestheticDialog.ERROR);
AestheticDialog.showToaster(this, "Your dialog Title", "Your message", AestheticDialog.SUCCESS);
AestheticDialog.showToaster(this, "Your dialog Title", "Your message", AestheticDialog.WARNING);
AestheticDialog.showToaster(this, "Your dialog Title", "Your message", AestheticDialog.INFO);
/// Dark Theme
AestheticDialog.showToasterDark(this, "Your dialog Title", "Your message", AestheticDialog.ERROR);
AestheticDialog.showToasterDark(this, "Your dialog Title", "Your message", AestheticDialog.SUCCESS);
AestheticDialog.showToasterDark(this, "Your dialog Title", "Your message", AestheticDialog.WARNING);
AestheticDialog.showToasterDark(this, "Your dialog Title", "Your message", AestheticDialog.INFO);
Drake :
AestheticDialog.showDrake(this, AestheticDialog.SUCCESS);
AestheticDialog.showDrake(this, AestheticDialog.ERROR);
Emoji :
AestheticDialog.showEmoji(this,"Your dialog Title", "Your message", AestheticDialog.SUCCESS);
AestheticDialog.showEmoji(this, "Your dialog Title", "Your message", AestheticDialog.ERROR);
/// Dark Theme
AestheticDialog.showEmojiDark(this,"Your dialog Title", "Your message", AestheticDialog.SUCCESS);
AestheticDialog.showEmojiDark(this, "Your dialog Title", "Your message", AestheticDialog.ERROR);
Emotion :
AestheticDialog.showEmotion(this,"Your dialog Title", "Your message", AestheticDialog.SUCCESS);
AestheticDialog.showEmotion(this, "Your dialog Title", "Your message", AestheticDialog.ERROR);
Rainbow :
AestheticDialog.showRainbow(this,"Your dialog Title", "Your message", AestheticDialog.SUCCESS);
AestheticDialog.showRainbow(this,"Your dialog Title", "Your message", AestheticDialog.ERROR);
AestheticDialog.showRainbow(this,"Your dialog Title", "Your message", AestheticDialog.WARNING);
AestheticDialog.showRainbow(this,"Your dialog Title", "Your message", AestheticDialog.INFO);
3.2 效果如下
Flash DialogConnectify DialogToaster Dialog
Emotion DialogDrake DialogEmoji Dialog
更多詳情使用方法請看Github:https://github.com/gabriel-TheCode/AestheticDialogs
N4. EasyReveal
從名字就知道,這是一個提供reveal動畫效果的庫,它的厲害之處在於可以提供不同尺寸、不同形狀的reveal動畫,並且還可以在定義它在屏幕任意位置開始和結束動畫。
4.1 如何使用?
在build.gradle 中添加如下依賴:
dependencies {
...
implementation 'com.github.Chrisvin:EasyReveal:1.2'
}
然後,xml中,需要添加顯示或者隱藏動畫的View應該包裹在EasyRevealLinearLayout中:
<com.jem.easyreveal.layouts.EasyRevealLinearLayout
...
app:clipPathProvider="star" // possible values: circular, linear, random_line, star, sweep & wave
app:revealAnimationDuration="2000"
app:hideAnimationDuration="1500" >
<!-- The views to be revealed/hidden go here -->
</com.jem.easyreveal.layouts.EasyRevealLinearLayout>
<!-- Similarly for com.jem.easyreveal.layouts.EasyRevealConstraintLayout & com.jem.easyreveal.layouts.EasyRevealFrameLayout -->
也可以在代碼中添加:
val revealLayout = EasyRevealLinearLayout(this)
// Set the ClipPathProvider that is used to clip the view for reveal animation
revealLayout.clipPathProvider = StarClipPathProvider(numberOfPoints = 6)
// Set the duration taken for reveal animation
revealLayout.revealAnimationDuration = 1500
// Set the duration taken for hide animation
revealLayout.hideAnimationDuration = 2000
// Set listener to get updates during reveal/hide animation
revealLayout.onUpdateListener = object: RevealLayout.OnUpdateListener {
override fun onUpdate(percent: Float) {
Toast.makeText(this@MainActivity, "Revealed percent: $percent", Toast.LENGTH_SHORT).show()
}
}
// Start reveal animation
revealLayout.reveal()
// Start hide animation
revealLayout.hide()
4.2效果圖
Emotion DialogDrake DialogEmoji Dialog
更多詳細使用信息請看Github:https://github.com/Chrisvin/EasyReveal
No5. Android ColorX
Android ColorX 以Kotlin 擴展函數的形式提供了一些重要的獲取顏色的方法。通過提供不同顏色格式(RGB,HSV,CYMK等)的轉換功能,它使開發變得更加輕鬆。該庫的USP具有以下功能:
- 顏色的不同陰影和色調。
- 較深和較淺的陰影。
- 顏色的補碼
5.1 如何使用?
在build.gradle 中添加如下依賴:
dependencies {
implementation 'me.jorgecastillo:androidcolorx:0.2.0'
}
在代碼中,一系列的轉換方法:
val color = Color.parseColor("#e91e63")
val rgb = color.asRgb()
val argb = color.asArgb()
val hex = color.asHex()
val hsl = color.asHsl()
val hsla = color.asHsla()
val hsv = color.asHsv()
val cmyk = color.asCmyk()
val colorHsl = HSLColor(hue = 210f, saturation = 0.5f, lightness = 0.5f)
val colorInt = colorHsl.asColorInt()
val rgb = colorHsl.asRgb()
val argb = colorHsl.asArgb()
val hex = colorHsl.asHex()
val cmyk = colorHsl.asCmyk()
val hsla = colorHsl.asHsla()
val hsv = colorHsl.asHsv()
5.2 效果圖
No6. AnimatedBottomBar
這是一個帶動畫的底部導航欄庫。它使你可以以編程方式以及通過XML添加和刪除選項卡。此外,我們可以輕鬆地從BottomBar攔截選項卡。限制訪問應用程序導航中的高級區域時,“攔截”標籤非常有用。流暢的動畫提供了許多自定義選項,從動畫插值器到設置波紋效果。
6.1 如何使用?
在build.gradle 中添加如下依賴:
dependencies {
implementation 'nl.joery.animatedbottombar:library:1.0.8'
}
在xml文件中添加AnimatedBottomBar和自定義屬性
<nl.joery.animatedbottombar.AnimatedBottomBar
android:id="@+id/bottom_bar"
android:background="#FFF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:abb_selectedTabType="text"
app:abb_indicatorAppearance="round"
app:abb_indicatorMargin="16dp"
app:abb_indicatorHeight="4dp"
app:abb_tabs="@menu/tabs"
app:abb_selectedIndex="1" />
在res/menu目錄下定義tabs.xml文件:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/tab_home"
android:icon="@drawable/home"
android:title="@string/home" />
<item
android:id="@+id/tab_alarm"
android:icon="@drawable/alarm"
android:title="@string/alarm" />
<item
android:id="@+id/tab_bread"
android:icon="@drawable/bread"
android:title="@string/bread" />
<item
android:id="@+id/tab_cart"
android:icon="@drawable/cart"
android:title="@string/cart" />
</menu>
最後,代碼中添加tab
// Creating a tab by passing values
val bottomBarTab1 = AnimatedBottomBar.createTab(drawable, "Tab 1")
// Creating a tab by passing resources
val bottomBarTab2 = AnimatedBottomBar.createTab(R.drawable.ic_home, R.string.tab_2, R.id.tab_home)
6.2 效果圖
tab1tab2
No7. RateBottomSheet
有時候,爲了推廣我們的應用,我們需要讓用戶跳轉到應用商店爲我們的APP打分,傳統的對話框用戶體驗很不好,而本庫則是用BottomSheet來進行提示,它位於底部縮略區域,用戶體驗很好。
7.1 如何使用呢?
在build.gradle 中添加如下依賴:
dependencies {
implementation 'com.mikhaellopez:ratebottomsheet:1.1.0'
}
然後修改默認的string資源文件來改變顯示文案:
<resources>
<string name="rate_popup_ask_title">Like this App?</string>
<string name="rate_popup_ask_message">Do you like using this application?</string>
<string name="rate_popup_ask_ok">Yes I do</string>
<string name="rate_popup_ask_no">Not really</string>
<string name="rate_popup_title">Rate this app</string>
<string name="rate_popup_message">Would you mind taking a moment to rate it? It won\'t take more than a minute. Thanks for your support!</string>
<string name="rate_popup_ok">Rate it now</string>
<string name="rate_popup_later">Remind me later</string>
<string name="rate_popup_no">No, thanks</string>
</resources>
代碼中使用:
RateBottomSheetManager(this)
.setInstallDays(1) // 3 by default
.setLaunchTimes(2) // 5 by default
.setRemindInterval(1) // 2 by default
.setShowAskBottomSheet(false) // True by default
.setShowLaterButton(false) // True by default
.setShowCloseButtonIcon(false) // True by default
.monitor()
// Show bottom sheet if meets conditions
// With AppCompatActivity or Fragment
RateBottomSheet.showRateBottomSheetIfMeetsConditions(this)
7.2 效果圖
No8. TransformationLayout
這是一個用於Activity或者Fragment 以及View切換的過渡動畫庫,效果非常炫,它使用Material Design的運動系統過渡模式來創建變形動畫。該庫提供了用於綁定目標視圖,設置淡入淡出和路徑運動方向以及許多其他自定義選項的屬性。
8.1 如何使用?
在build.gradle 中添加如下依賴:
dependencies {
implementation "com.github.skydoves:transformationlayout:1.0.4"
}
然後,需要將我們需要添加過渡動畫的View包裹到 TransformationLayout:
<com.skydoves.transformationlayout.TransformationLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:transformation_targetView="@+id/my_cardView" // sets a target view.
app:transformation_duration="450" // sets a duration of the transformation.
app:transformation_direction="auto" // auto, entering, returning
app:transformation_fadeMode="in" // in, out, cross, through
app:transformation_fitMode="auto" // auto, height, width
app:transformation_pathMode="arc" // arc, linear
>
<!-- other views -->
</com.skydoves.transformationlayout.TransformationLayout>
比如我們要將一個fab 過渡到一個card卡片,佈局如下:
<com.skydoves.transformationlayout.TransformationLayout
android:id="@+id/transformationLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:transformation_duration="550"
app:transformation_targetView="@+id/myCardView">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorPrimary"
android:src="@drawable/ic_write"/>
</com.skydoves.transformationlayout.TransformationLayout>
<com.google.android.material.card.MaterialCardView
android:id="@+id/myCardView"
android:layout_width="240dp"
android:layout_height="312dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="30dp"
app:cardBackgroundColor="@color/colorPrimary" />
重點來了,綁定視圖,將一個targetView綁定到TransformationLayout有2種方式:
- 通過在xml中指定屬性:
app:transformation_targetView="@+id/myCardView"
- 在代碼中綁定
transformationLayout.bindTargetView(myCardView)
當我們點擊fab時,在監聽器中調用startTransform()開始過渡動畫,finishTransform()開始結束動畫。
// start transformation when touching the fab.
fab.setOnClickListener {
transformationLayout.startTransform()
}
// finish transformation when touching the myCardView.
myCardView.setOnClickListener {
transformationLayout.finishTransform()
}
8.2 效果圖
No9. Donut
這個一個可以展示多個數據集的圓環形控件,具有精細的顆粒控制、間隙功能、動畫選項以及按比例縮放其值的功能。可以用於項目中的一些數據統計。
9.1 如何使用?
在build.gradle 中添加如下依賴:
dependencies
implementation("app.futured.donut:library:$version")
}
然後在佈局文件中添加View:
<app.futured.donut.DonutProgressView
android:id="@+id/donut_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:donut_bgLineColor="@color/cloud"
app:donut_gapWidth="20"
app:donut_gapAngle="270"
app:donut_strokeWidth="16dp"/>
然後在代碼中設置數據:
val dataset1 = DonutDataset(
name = "dataset_1",
color = Color.parseColor("#FB1D32"),
amount = 1f
)
val dataset2 = DonutDataset(
name = "dataset_2",
color = Color.parseColor("#FFB98E"),
amount = 1f
)
donut_view.cap = 5f
donut_view.submitData(listOf(dataset1, dataset2))
9.2 效果圖
No10. CurveGraphView
CurveGraphView 是一個帶有炫酷動畫統計圖表庫,除了性能出色並具有許多樣式選項之外,該庫還支持單個平面內的多個線圖。
多個折線圖對於比較不同股票,共同基金,加密貨幣等的價格非常有用。
10.1 如何使用?
1、在build.gradle 中添加如下依賴:
dependencies {
implementation 'com.github.swapnil1104:CurveGraphView:{current_lib_ver}'
}
2、在xml文件中添加布局:
<com.broooapps.graphview.CurveGraphView
android:id="@+id/cgv"
android:layout_width="0dp"
android:layout_height="250dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
然後在代碼中添加各種配置項
curveGraphView = findViewById(R.id.cgv);
curveGraphView.configure(
new CurveGraphConfig.Builder(this)
.setAxisColor(R.color.Blue) // Set X and Y axis line color stroke.
.setIntervalDisplayCount(7) // Set number of values to be displayed in X ax
.setGuidelineCount(2) // Set number of background guidelines to be shown.
.setGuidelineColor(R.color.GreenYellow) // Set color of the visible guidelines.
.setNoDataMsg(" No Data ") // Message when no data is provided to the view.
.setxAxisScaleTextColor(R.color.Black) // Set X axis scale text color.
.setyAxisScaleTextColor(R.color.Black) // Set Y axis scale text color
.build()
););
3、 提供數據集
PointMap pointMap = new PointMap();
pointMap.addPoint(0, 100);
pointMap.addPoint(1, 500);
pointMap.addPoint(5, 800);
pointMap.addPoint(4, 600);
10.2 效果圖
效果1
效果2
如果你有其他需要的話,也可以在 GitHub 上查看。
總結
以上就是本期的開源庫推薦,別忘了添加到你的收藏夾喲!如果你覺得還不錯,就三連支持一下吧!如果你還有一些有意思的,效果特別炫酷的庫,也歡迎評論區留言推薦,感謝閱讀,祝編碼愉快!
---END---