Truffle Shuffle 是一個 Android UI 組件卡庫庫,帶有有趣的動畫。圖庫很容易定制,並且是基於數組中對象的數量和這些對象內的內容的數據驅動的。卡片庫使用帶有自定義視圖屬性的定制 Android ViewGroup 來指定各個卡片的大小占 ViewGroup 大小的百分比。此卡片庫用於 TurboTax 的產品系列中的移動應用程序。 Truffle Shuffle 100% 用 Kotlin 編寫!
要運行示例項目,請克隆存儲庫並運行 Android 應用程序安卓工作室在模擬器上。 你可以玩這個例子
- 更改 app/src/main/res/layout/card_layout.xml 中卡片的佈局
- 在 app/src/main/kotlin/com/intuit/truffle/shuffle/MainActivity.kt 的 getCardDetails() 中更改數組中的卡片數量
- 在 app/src/main/res/values/card_view_group_percentages.xml 中更改視圖組的百分比
要為該項目做出貢獻,請確保提交的代碼符合該項目的格式標準。
要重新格式化或檢查提交的代碼是否合規,請遵循以下選項之一:
使用 Gradle 任務(推薦 -ktlint 文檔):
./gradlew ktlint
Use this command to check the formatting rules are covered
/gradlew ktlintFormat
Use this command to re-format code that is not compliant with this project's formatting rules.
使用 ktlint 引擎 (ktlint 文檔):
ktlint
Use this command to check the formatting rules are covered
ktlint "src/**/*.kt" "!src/**/*Test.kt"
Check only certain locations (prepend ! to negate the pattern)
ktlint -F
Use this command to re-format code that is not compliant with this project's formatting rules. (if some errors cannot be fixed automatically they will be printed to stderr)
ktlint -F "src/**/*.kt"
Use this command to re-format certain locations (prepend ! to negate the pattern) . (if some errors cannot be fixed automatically they will be printed to stderr)
ktlint --install-git-pre-commit-hook
Install git hook to automatically check files for style violations on commit.
要將其添加到您自己的 Android 應用程序,請完成以下步驟:
-
將依賴項添加到項目的 build.gradle 文件的 dependencies 下:
dependencies { implementation 'com.intuit.truffleshuffle:truffleshuffle:1.0.0' }
並確保將 jcenter() 添加到您的應用程序 build.gradle
repositories {
jcenter()
}
- 將 com.intuit.truffleshuffle.CardViewGroup 添加到您想要卡片庫的 xml 文件中,例如 app/src/main/res/layout/activity_main.xml
- 將你想要的百分比添加到 xml 文件中 CardViewGroup 的自定義屬性
- 自定義:dashboardCardHeightPercentage,自定義:widthPercentage,自定義:topSpacingPercentage,自定義:bottomSpacingPercentage
- 將你想要的百分比添加到 xml 文件中 CardViewGroup 的自定義屬性
- 為卡片內容添加一個 xml 佈局 (card_layout.xml),類似於 app/src/main/res/layout/card_layout.xml
- Create a folder cardGallery with 2 files:
- CardContent 類似於 app/src/main/kotlin/com/intuit/truffle/shuffle/cardGallery/CardContent.kt
- 這是卡片內容的數據對象
- CustomizeAdapter 類似於 app/src/main/kotlin/com/intuit/truffle/shuffle/cardGallery/CustomizeAdapter.kt
- 構造函數應該採用 ArrayList並且應該擴展 CardContentAdapter
- 覆蓋 getViewContent() 函數以將 cardContent 中的數據內容設置為 card_layout.xml 中的視圖,即。在 textView 中設置文本
- CardContent 類似於 app/src/main/kotlin/com/intuit/truffle/shuffle/cardGallery/CardContent.kt
- 在您將使用此 UI 組件的 Activity 中:
- 實例化您剛剛定義的 CustomizeAdapter 並傳入 CardContents 的數組列表和卡內的資源 ID,即。 R.layout.card_layout
- 使用 findViewById() 在您剛剛使用 CardViewGroup 創建的 CustomizeAdapter 上調用 setupAdapter()
- 現在 TruffleShuffle UI 組件可以使用了!
- 如果你需要幫忙, 打開一個問題並標記為
help wanted
. - 如果你發現一個錯誤, 打開一個問題並標記為
bug
. - 如果你有一個功能請求, 打開一個問題並標記為
feature
. - 如果你想貢獻,請參考貢獻文檔並提交拉取請求。
- 為了提交拉取請求,請分叉此回購併從分叉的回購中提交 PR。
- 詳細說明您的 PR 修復/增強/添加的內容。
- 在我們合併之前,每個 PR 都必須獲得批准。
感謝這些優秀的人(表情符號鍵):
該項目遵循所有貢獻者規格。歡迎任何形式的貢獻!