ShadowLayout Android Library

repository·master·Indexed 25 days ago

https://github.com/lihangleo2/shadowlayout

An Android library providing highly customizable shadows and shape/selector capabilities for any View. It allows developers to define shadows, corner radii, gradients, and interaction states (pressed, selected, ripple) directly through the layout component, reducing the need for complex drawable XML files. Features include TextView binding for state-based text/color changes, view clipping for custom rounded corners, and support for AndroidX (v3.4.0+).

Tokens
4K
Snippets
9
Records
22
Agent score
86%

What's inside ShadowLayout

  1. Overview of ShadowLayout features

    master

    ShadowLayout is a versatile layout component that allows any View to enjoy customizable shadows and system-level shape/selector functionality without needing extra drawable files.

    Shadow Customization:

    • Modify shadow color values.
    • Set uniform or individual corner radii.
    • Adjust X and Y offsets.
    • Control shadow diffusion (size).
    • Hide shadows on specific sides or completely.
    • Dynamically modify shadows via code.

    Shape and Selector Features:

    • Supports pressed, selected, and ripple states.
    • Background color and stroke (border) settings.
    • Gradient background support.
    • Clickable/non-clickable state backgrounds.
    • Binding to TextView to react to text or color changes.
    • Support for image backgrounds and image selectors.
    • View clipping (useful for players or custom rounded corners).
  2. Install ShadowLayout via JitPack

    master

    To use ShadowLayout in your Android project, add the JitPack repository to your project-level build.gradle and the dependency to your app-level build.gradle.

    // Project build.gradle
    allprojects {
        repositories {
            maven { url 'https://jitpack.io' }
        }
    }
    
    // App build.gradle
    dependencies {
        implementation 'com.github.lihangleo2:ShadowLayout:2.1.8'
    }
  3. Integrate ShadowLayout as a module to resolve Glide conflicts

    master

    Follow these steps to import shadowLibrary as a local module and configure the Glide version:

    1. Download the demo project and open it in Android Studio.
    2. Go to File -> New -> Import Module.
    3. Select the shadowLibrary folder and click Finish.
    4. In your app's build.gradle file, add the following dependency:
      implementation project(':shadowLibrary')
    5. Open the build.gradle file located inside the shadowLibrary module and update the Glide version to match your project's version.
    implementation project(':shadowLibrary')
  4. Resolve Glide version conflicts using Library integration

    master

    If you encounter Glide version conflicts when using ShadowLayout, integrate the project as a module instead of a remote dependency. This allows you to manually override the Glide version used by the library to match your project's requirements.

    Note: If you upgrade to a significantly newer version of Glide, you may need to update the Glide loading methods within GlideRoundUtils inside the shadowLibrary module to maintain compatibility.

  5. Basic usage of SmartLoadingView

    master

    To use SmartLoadingView in a standard workflow (like a follow button), set up the view in XML and control the loading state via code.

    1. Start loading: Call startLoading() when the user clicks the button to initiate the loading animation.
    2. Finish successfully: Call finishLoading() (or finishLoading(true)) when the network request succeeds.
    3. Finish with failure: Call finishLoading(false) when the network request fails.
  6. Install ShadowLayout via Gradle

    master

    To use ShadowLayout in your Android project, follow these two steps:

    1. Add the JitPack repository to your project-level build.gradle:
    allprojects {
        repositories {
            maven { url 'https://jitpack.io' }
        }
    }
    1. Add the dependency to your app-level build.gradle. Use the AndroidX version for modern projects:
    dependencies {
        // AndroidX version
        implementation 'com.github.lihangleo2:ShadowLayout:3.4.5'
    
        // Non-AndroidX version
        // implementation 'com.github.lihangleo2:ShadowLayout:3.3.3'
    }
    implementation 'com.github.lihangleo2:ShadowLayout:3.4.5'
  7. Clip Views with Custom Corner Radii

    master

    ShadowLayout can be used to clip any child view (like a VideoView) to specific corner radii.

    To clip a view without the default white background and to avoid click conflicts in lists (like RecyclerView), use:

    • app:hl_layoutBackground="@color/transparent"
    • app:clickable="false"

    Example:

    <com.lihang.ShadowLayout
        android:layout_width="match_parent"
        android:layout_height="259dp"
        app:hl_cornerRadius_leftTop="12dp"
        app:hl_cornerRadius_rightTop="12dp"
        app:hl_layoutBackground="@android:color/transparent"
        app:clickable="false">
    
        <VideoView
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
    </com.lihang.ShadowLayout>
    <com.lihang.ShadowLayout
        android:id="@+id/shadowlayout_Container"
        android:layout_width="match_parent"
        android:layout_height="@dimen/dp_259"
        app:hl_cornerRadius_leftTop="@dimen/dp_12"
        app:hl_cornerRadius_rightTop="@dimen/dp_12"
        app:hl_layoutBackground="@color/transparent"
        app:clickable="false"
        >
        <com.iccapp.module.common.widget.video.VideoView
            android:id="@+id/video_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />
    </com.lihang.ShadowLayout>
  8. Configure SmartLoadingView button types

    master

    Use the app:hl_button_type attribute in XML to define the animation behavior of the SmartLoadingView.

    Available modes:

    • smart_full_screen: Full-screen diffusion animation for page transitions (does not support 'follow/unfollow' logic).
    • smart_button: Standard button animation (supports follow/unfollow logic).
    • smart_tick: TikTok-style checkmark animation (supports follow/unfollow).
    • smart_tick_hide: Checkmark animation followed by hiding the button (supports follow/unfollow).
    • smart_tick_center_hide: Checkmark animation, hiding, and then moving to the center of the screen (supports follow/unfollow).
    app:hl_button_type="smart_button"
  9. Fix dependency issues for ShadowLayout version 3.2.4

    master

    If you are using version 3.2.4 and encounter dependency errors caused by JitPack/Gradle 7.0 compatibility issues, you must use the specific release suffix 3.2.4rz to resolve the issue. Alternatively, upgrading to version 3.3.2 or higher is recommended as the fix is included in those versions.

    implementation 'com.github.lihangleo2:ShadowLayout:3.2.4rz'
  10. Basic usage of ShadowLayout

    master

    Wrap your target view with com.lihang.ShadowLayout to apply customizable shadows. The layout supports corner radius, shadow color, background color, and shadow spread (limit).

    <com.lihang.ShadowLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:hl_cornerRadius="18dp"
        app:hl_shadowColor="#2aff0000"
        app:hl_shadowBackColor="#fff"
        app:hl_shadowLimit="5dp">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:gravity="center"
            android:text="定制化你的阴影"
            android:textColor="#000" />
    
    </com.lihang.ShadowLayout>