Android 新拟态UI (Neumorphism)

前言

本文转自github,只是进行了图片的处理和部分翻译,已获作者授权
截至首次发文前找到的原作者的文章地址-May,17,2020若找到本文章更新的时间节点,请私信我更新。
原作者github地址
文末附源码下载地址,免费。
在这里插入图片描述

Android上的拟态化UI


This is the experimental codes to build Neumorphism designs in Android.
Not a library. Just sample project now(目前只是示例项目).


Preview

Light | Dark

添加依赖

在项目级 build.gradle 添加以下依赖:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

然后, 在 build.gradle中添加以下依赖

dependencies {
//截至首次发文前latest_version为0.3.0
    implementation 'com.github.fornewid:neumorphism:{latest_version}'
}

Features

  • 为组件绘制阴影实现新拟态化效果。
    支持以下组件:
    • ViewGroup: CardView
    • View: Button, FloatingActionButton, ImageView
  • 在Text上绘制阴影来实现TextView的新拟态化。

如果您需要更多功能或要修复错误,请单击 new issue并报告给我!

示例

<soup.neumorphism.NeumorphCardView
    // 预定义样式
    style="@style/Widget.Neumorph.CardView"

    // 设置elevation和color
    app:neumorph_shadowElevation="6dp"
    app:neumorph_shadowColorLight="@color/solid_light_color"
    app:neumorph_shadowColorDark="@color/solid_dark_color"

    // 设置光源 lightSource
    app:neumorph_lightSource="leftTop|leftBottom|rightTop|rightBottom"

    // 设置Shape类型和corner size
    app:neumorph_shapeType="{flat|pressed|basin}"
    app:neumorph_shapeAppearance="@style/CustomShapeAppearance"

    // 设置 background 或 stroke
    app:neumorph_backgroundColor="@color/background_color"
    app:neumorph_strokeColor="@color/stroke_color"
    app:neumorph_strokeWidth="@dimen/stroke_width"

使用插图以避免修剪阴影
    // 使用 inset 以避免阴影被裁剪. (default=12dp)
    app:neumorph_inset="12dp"
    app:neumorph_insetStart="12dp"
    app:neumorph_insetEnd="12dp"
    app:neumorph_insetTop="12dp"
    app:neumorph_insetBottom="12dp"

    // Use a padding. (default=12dp)
    android:padding="12dp">

    <!-- NeumorphCardView extends FrameLayout. So you can wrap childrens like this. -->
    <ConstraintLayout />
</soup.neumorphism.NeumorphCardView>

<style name="CustomShapeAppearance">
    <item name="neumorph_cornerFamily">{rounded|oval}</item>
    <item name="neumorph_cornerSize">32dp</item>

    <!-- Or if wants different radii depending on the corner. -->
    <item name="neumorph_cornerSizeTopLeft">16dp</item>
    <item name="neumorph_cornerSizeTopRight">16dp</item>
    <item name="neumorph_cornerSizeBottomLeft">16dp</item>
    <item name="neumorph_cornerSizeBottomRight">16dp</item>
</style>
  • 光源(LightSource)
LEFT_TOPLEFT_BOTTOMRIGHT_TOPRIGHT_BOTTOM
  • 阴影类型(ShapeType)
FLATPRESSEDBASIN

License

Copyright 2020 SOUP

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you 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.

GitHub源码下载地址

  • 3
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值