项目作者: rasoulmiri

项目描述 :
Skeleton Android
高级语言: Java
项目地址: git://github.com/rasoulmiri/Skeleton.git
创建时间: 2017-08-24T09:24:35Z
项目社区:https://github.com/rasoulmiri/Skeleton

开源协议:Apache License 2.0

下载


Skeleton Android

Simple yet powerful skeleton animation for all view in android



Android Arsenal
Minimum API 17



alt tag



See demo project


See demo APK

Setup :

Add JitPack repository in your root build.gradle at the end of repositories.

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url 'https://jitpack.io' }
  5. }
  6. }

Add dependency in your app level build.gradle.

  1. dependencies {
  2. compile 'com.github.rasoulmiri:Skeleton:v1.1.4'
  3. }

Usage XML:

Step 1:

add name space on top layout

  1. xmlns:Skeleton="http://schemas.android.com/apk/res-auto"

Step 2:

use SkeletonGroup and SkeletonView in layout

  1. <io.rmiri.skeleton.SkeletonGroup
  2. android:layout_width="match_parent"
  3. android:layout_height="wrap_content">
  4. <io.rmiri.skeleton.SkeletonView ...>
  5. <View ... ></View>
  6. </io.rmiri.skeleton.SkeletonView>
  7. <io.rmiri.skeleton.SkeletonView ...>
  8. <View ... ></View>
  9. </io.rmiri.skeleton.SkeletonView>
  10. </io.rmiri.skeleton.SkeletonGroup>

Example:

  1. <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:Skeleton="http://schemas.android.com/apk/res-auto"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. android:layout_width="match_parent"
  5. android:layout_height="wrap_content"
  6. app:cardBackgroundColor="@color/white"
  7. app:cardCornerRadius="10dp"
  8. app:cardElevation="10dp"
  9. app:cardUseCompatPadding="true"
  10. app:contentPadding="0dp">
  11. <io.rmiri.skeleton.SkeletonGroup
  12. android:id="@+id/skeletonGroup"
  13. android:layout_width="match_parent"
  14. android:layout_height="wrap_content"
  15. Skeleton:SK_BackgroundViewsColor="#EEEEEE"
  16. Skeleton:SK_animationAutoStart="true"
  17. Skeleton:SK_animationDirection="LTR"
  18. Skeleton:SK_animationDuration="1000"
  19. Skeleton:SK_animationFinishType="gradient"
  20. Skeleton:SK_animationNormalType="gradient"
  21. Skeleton:SK_backgroundMainColor="@android:color/transparent"
  22. Skeleton:SK_highLightColor="#DEDEDE">
  23. <RelativeLayout
  24. android:layout_width="match_parent"
  25. android:layout_height="wrap_content">
  26. <io.rmiri.skeleton.SkeletonView
  27. android:id="@+id/skeletonViewPhoto"
  28. android:layout_width="match_parent"
  29. android:layout_height="300dp"
  30. Skeleton:SK_cornerRadius="0dp"
  31. Skeleton:SK_padding="0dp"
  32. Skeleton:SK_shapeType="rect">
  33. <android.support.v7.widget.AppCompatImageView
  34. android:layout_width="match_parent"
  35. android:layout_height="match_parent"
  36. android:scaleType="centerCrop"
  37. app:srcCompat="@drawable/photoTest" ></android.support.v7.widget.AppCompatImageView>
  38. </io.rmiri.skeleton.SkeletonView>
  39. <io.rmiri.skeleton.SkeletonView
  40. android:layout_width="match_parent"
  41. android:layout_height="wrap_content"
  42. android:layout_below="@+id/skeletonViewPhoto"
  43. Skeleton:SK_cornerRadius="10dp"
  44. Skeleton:SK_padding="5dp"
  45. Skeleton:SK_shapeType="rect">
  46. <TextView
  47. android:layout_width="match_parent"
  48. android:layout_height="wrap_content"
  49. android:layout_alignParentBottom="true"
  50. android:layout_alignParentEnd="true"
  51. android:text="Title" ></TextView>
  52. </io.rmiri.skeleton.SkeletonView>
  53. </RelativeLayout>
  54. </io.rmiri.skeleton.SkeletonGroup>
  55. </android.support.v7.widget.CardView>

Final step

Nothing really! Just build your app, watch the magic happen ;) .

Configure XML

SkeletonGroup

  • SK_animationAutoStart: true or false | default value true
  • SK_animationDuration: time animation | default 1000 millisecond
  • SK_animationDirection: RTL,LTR,BTT,TTB | default value is LTR
  • SK_animationNormalType: none,alpha,gradient | default value is gradient
  • SK_animationFinishType: none,alpha,gradient | default value is gradient
  • SK_backgroundMainColor: background total SkeletonGroup
  • SK_BackgroundViewsColor: background SkeletonViews in this SkeletonGroup
  • SK_highLightColor: highLight color animation

SkeletonView

  • SK_shapeType: rect, oval,text | defult value rect
  • SK_cornerRadius: just use for shape type rect | defult value 0dp
  • SK_cornerRadiusTopLeft
  • SK_cornerRadiusTopRight
  • SK_cornerRadiusBottomLeft
  • SK_cornerRadiusBottomLRight
  • SK_padding: padding view if SK_shapeType equals rect | default value is 0dp
  • SK_paddingTop
  • SK_paddingRight
  • SK_paddingLeft
  • SK_paddingBottom
  • SK_textLineNumber: just use for shape type text | default value is 3
  • SK_textLineLastWidth: full, threeQuarters, half, quarter | default value is threeQuarters
  • SK_textLineHeight: height of line | default value is 24dp
  • SK_textLineSpaceVertical: space vertical between lines | default value is threeQuarters 4dp

Usage Java:

Step 1:

Create SkeletonViewGroup

  1. SkeletonViewGroup skeletonViewGroup = new SkeletonViewGroup(context);

Step 2:

Create ArrayList for keep views config

  1. ArrayList<SkeletonModel> skeletonModels = new ArrayList<>();

Step 3:

Add views to skeletonModels
You should add views to skeleton models by 3 ways.

Way 1: Defined by 1 view

  • setChildView(view)
    1. skeletonModels.add(new SkeletonModelBuilder()
    2. .setChildView(view1)
    3. .build())

Way 2: Defined by 1 view and custom width and height

  • setChildView(view)
  • setCustomWidth(float)
  • setCustomHeigh(float)
    1. skeletonModels.add(new SkeletonModelBuilder()
    2. .setChildView(view1)
    3. .setCustomWidth(ConverterUnitUtil.dpToPx(getApplicationContext(), 140f))
    4. .setCustomHeight(ConverterUnitUtil.dpToPx(getApplicationContext(), 50f))
    5. .build());

Way 3: Defined by 1 view and fill parent

  • setChildView(view)
  • setIsMatchViewBoolean(boolean)
    1. skeletonModels.add(new SkeletonModelBuilder()
    2. .setChildView(view1)
    3. .setIsMatchViewBoolean(true)
    4. .build());

Way 4: Defined by 2 views (draw from left-top startView to right-bottom endView)

  • setStartView(view)
  • setEndView(view)

    1. skeletonModels.add(new SkeletonModelBuilder()
    2. .setStartView(view1)
    3. .setEndView(view2)
    4. .build());

    Step 4:

    Add models to skeletonViewGroup

    1. skeletonViewGroup.setSkeletonModels(skeletonModels);

    Step 5:

    Add SkeletonViewGroup to layout

    1. ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
    2. ViewGroup.LayoutParams.MATCH_PARENT,
    3. ViewGroup.LayoutParams.MATCH_PARENT);
    4. mainLayoutExample.addView(skeletonViewGroup, layoutParams);

    Final step

    Nothing really! Just build your app, watch the magic happen ;) .

    Example:

  1. SkeletonViewGroup skeletonViewGroup = new SkeletonViewGroup(getApplicationContext());
  2. ArrayList<SkeletonModel> skeletonModels = new ArrayList<>();
  3. // Add view
  4. skeletonModels.add(new SkeletonModelBuilder()
  5. .setChildView(btn1)
  6. .setIsMatchViewBoolean(true) //MatchView
  7. .build());
  8. skeletonModels.add(new SkeletonModelBuilder()
  9. .setStartView(btn2) // AddView start
  10. .setEndView(btn3)// AddView end
  11. .build());
  12. skeletonModels.add(new SkeletonModelBuilder()
  13. .setChildView(btn4)// AddView
  14. .setCustomWidth(ConverterUnitUtil.dpToPx(getApplicationContext(), 140f)) // CustomWidth
  15. .setCustomHeight(ConverterUnitUtil.dpToPx(getApplicationContext(), 50f)) // CustomHeight
  16. .build());
  17. skeletonViewGroup.setSkeletonModels(skeletonModels);
  18. // Add SkeletonViewGroup
  19. ViewGroup.LayoutParams layout = new ViewGroup.LayoutParams(
  20. ViewGroup.LayoutParams.MATCH_PARENT,
  21. ViewGroup.LayoutParams.MATCH_PARENT)
  22. mainLayout.addView(skeletonViewGroup, layout);

SkeletonModelBuilder

  1. new SkeletonModelBuilder()
  2. .setChildView(view)
  3. .setCustomHeight(float)
  4. .setCustomHeight(float)
  5. .setStartView(view)
  6. .setEndView(view)
  7. .setIsMatchViewBoolean(boolean)
  8. .setShapeType(SkeletonModel.SHAPE_TYPE_RECT) -> SHAPE_TYPE_RECT, SHAPE_TYPE_OVAL, SHAPE_TYPE_TEXT
  9. .setPadding(float)
  10. .setPaddingTop(float)
  11. .setPaddingBottom(float)
  12. .setPaddingLeft(float)
  13. .setPaddingRight(float)
  14. .setCornerRadius(int)
  15. .setCornerRadiusTopRight(int)
  16. .setCornerRadiusTopLeft(int)
  17. .setCornerRadiusBottomLRight(int)
  18. .setCornerRadiusBottomLeft(int)
  19. .build();
  1. skeletonGroup.setSkeletonListener(new SkeletonGroup.SkeletonListener() {
  2. @Override
  3. public void onStartAnimation() {
  4. ...
  5. }
  6. @Override
  7. public void onFinishAnimation() {
  8. ...
  9. }
  10. });

for use in RecyclerView and Adapter See sample 1 activity in this project

Contributing

You are welcome to contribute with issues, PRs or suggestions.