Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The easiest library to show skeleton screens in an Android app.

License

NotificationsYou must be signed in to change notification settings

ericktijerou/koleton

Repository files navigation

The easiest library to show skeleton screens in an Android app.

KotlinMinimum SDK Version

An Android library that provides an easy way to show skeleton of any view.

Koleton is an acronym for:Kotlin skeleton.

Made with ❤ byericktijerou.

imgimgimg

Installation

You candownload and installKoleton withMaven Central andGradle:

// In your module's `build.gradle.kts`dependencies {    implementation("com.ericktijerou.koleton:koleton:1.0.0-beta01")}

Make sure to includemavenCentral() in your repositories

repositories {  mavenCentral()}

Quick Start

To load the skeleton of aView, use theloadSkeleton extension function:

// ConstraintLayoutconstraintLayout.loadSkeleton()// TextViewtextView?.loadSkeleton(length=20)// RecyclerViewrecyclerView.loadSkeleton(R.layout.item_example)

Skeletons can be configured with an optional trailing lambda:

// ConstraintLayoutconstraintLayout.loadSkeleton {    color(R.color.colorSkeleton)    cornerRadius(radiusInPixel)    shimmer(false)    lineSpacing(spacingInPixel)}// TextViewtextView?.loadSkeleton(length=20) {    color(R.color.colorSkeleton)...}// RecyclerViewrecyclerView.loadSkeleton(R.layout.item_example) {    itemCount(3)...}

To hide the skeleton, use thehideSkeleton extension function:

view.hideSkeleton()

SkeletonLoader

Koleton will lazily create aSkeletonLoader with the default values.If you want to set the default values, you can set a defaultSkeletonLoader instance by either:

// In your ApplicationclassMyApplication :Application(), SkeletonLoaderFactory {overridefunnewSkeletonLoader():SkeletonLoader {returnSkeletonLoader.Builder(this)...            .color(R.color.colorSkeleton)            .cornerRadius(radiusInPixel)            .build()    }}

Or callingKoleton.setSkeletonLoader

val skeletonLoader=SkeletonLoader.Builder(context)...    .color(R.color.colorSkeleton)    .cornerRadius(radiusInPixel)    .build()Koleton.setSkeletonLoader(skeletonLoader)

The defaultSkeletonLoader can be retrieved like so:

val skeletonLoader=Koleton.skeletonLoader(context)

Paging

Koleton works well withPaging library with the help ofKoletonView.

If you want to show a skeleton when you scroll to the bottom of your list, use thegenerateSkeleton extension function:

// In your PagedListAdapteroverridefunonCreateViewHolder(parent:ViewGroup,viewType:Int):RecyclerView.ViewHolder {val view=LayoutInflater.from(parent.context).inflate(R.layout.item_sample, parent,false)returnwhen (viewType) {...TYPE_SKELETON->SkeletonViewHolder(view.generateSkeleton())...    }}...classSkeletonViewHolder(valkoletonView:KoletonView) : RecyclerView.ViewHolder(koletonView) {funshowSkeleton() {        koletonView.showSkeleton()    }}

Shimmer effect

Koleton works with Facebook’sshimmer library. If you want to create a custom shimmer effect, you need to include in your dependencies:

// In your module's `build.gradle.kts`dependencies {    implementation("com.facebook.shimmer:shimmer:0.5.0")}

And set the custom shimmer in the lambda expression:

constraintLayout.loadSkeleton {val customShimmer=Shimmer.AlphaHighlightBuilder()        .setDirection(Shimmer.Direction.TOP_TO_BOTTOM)...        .build()    shimmer(customShimmer)}

img

You can find more information about Facebook's shimmer effect on theshimmer-android page.

License

   Copyright 2020 ericktijerou   Licensed under the Apache License, Version 2.0 (the "License");   you may not use this file except in compliance with the License.   You may obtain a copy of the License at       http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software   distributed under the License is distributed on an "AS IS" BASIS,   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the License for the specific language governing permissions and   limitations under the License.

[8]ページ先頭

©2009-2025 Movatter.jp