鸿蒙开源组件——指定控件形状设置

jacksky
发布于 2021-9-27 18:35
浏览
0收藏

ShapeOfView

项目介绍

  • 项目名称:ShapeOfView
  • 所属系列:openharmony 第三方组件适配移植
  • 功能:可将子控件设为多种形状的布局
  • 项目移植状态:主功能完成
  • 调用差异:无
  • 开发版本:sdk6,DevEco Studio2.2 beta1
  • 基线版本: Release 1.4.7

效果演示鸿蒙开源组件——指定控件形状设置-鸿蒙开发者社区

 

鸿蒙开源组件——指定控件形状设置-鸿蒙开发者社区鸿蒙开源组件——指定控件形状设置-鸿蒙开发者社区

安装教程

在moudle级别下的build.gradle文件中添加依赖

// 添加maven仓库
repositories {
   maven {
       url 'https://s01.oss.sonatype.org/content/repositories/releases/'
   }
}

// 添加依赖库
dependencies {
   implementation 'com.gitee.chinasoft_ohos:Shapeofview:1.0.0'   
}

在sdk6,DevEco Studio2.2 beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下

使用说明

Circle

鸿蒙开源组件——指定控件形状设置-鸿蒙开发者社区

 

<com.github.florent37.shapeofview.shapes.CircleView
        ohos:layout_width="150dp"
        ohos:layout_height="150dp"

        ohos:elevation="4dp"
        app:shape_circle_borderColor="@ohos:color/black"
        app:shape_circle_borderWidth="2dp">

            <!-- YOUR CONTENT -->

</com.github.florent37.shapeofview.shapes.CircleView>

 

RoundRect鸿蒙开源组件——指定控件形状设置-鸿蒙开发者社区

<com.github.florent37.shapeofview.shapes.RoundRectView
        ohos:layout_width="150dp"
        ohos:layout_height="100dp"
        ohos:elevation="4dp"
        app:shape_roundRect_bottomLeftRadius="10dp"
        app:shape_roundRect_bottomRightRadius="10dp"
        app:shape_roundRect_topLeftRadius="10dp"
        app:shape_roundRect_topRightRadius="10dp"
        
        app:shape_roundRect_borderColor="@ohos:color/black"
        app:shape_roundRect_borderWidth="2dp"
        >


            <!-- YOUR CONTENT -->

</com.github.florent37.shapeofview.shapes.RoundRectView>

Arc鸿蒙开源组件——指定控件形状设置-鸿蒙开发者社区

<com.github.florent37.shapeofview.shapes.ArcView
        ohos:layout_width="150dp"
        ohos:layout_height="100dp"
        ohos:elevation="4dp"
        app:shape_arc_cropDirection="outside"
        app:shape_arc_height="20dp"
        app:shape_arc_position="bottom"
        >

         <!-- YOUR CONTENT -->

</com.github.florent37.shapeofview.shapes.ArcView>

Diagonal鸿蒙开源组件——指定控件形状设置-鸿蒙开发者社区

<com.github.florent37.shapeofview.shapes.DiagonalView
        ohos:layout_width="150dp"
        ohos:layout_height="100dp"
        ohos:elevation="4dp"
        app:shape_diagonal_angle="10"
        app:shape_diagonal_direction="right" 
        app:shape_diagonal_position="bottom">

         <!-- YOUR CONTENT -->

</com.github.florent37.shapeofview.shapes.DiagonalView>

Triangle鸿蒙开源组件——指定控件形状设置-鸿蒙开发者社区

<com.github.florent37.shapeofview.shapes.TriangleView
         ohos:layout_width="150dp"
         ohos:layout_height="150dp"
         ohos:elevation="4dp"

         app:shape_triangle_percentBottom="0.5"
         app:shape_triangle_percentLeft="0"
         app:shape_triangle_percentRight="0">

            <!-- YOUR CONTENT -->

</com.github.florent37.shapeofview.shapes.TriangleView>

鸿蒙开源组件——指定控件形状设置-鸿蒙开发者社区

<com.github.florent37.shapeofview.shapes.StarView
        ohos:layout_width="150dp"
        ohos:layout_height="150dp"
        app:shape_star_noOfPoints="5">

         <!-- YOUR CONTENT -->

</com.github.florent37.shapeofview.shapes.StarView>

Dotted Edges with Cut Corners鸿蒙开源组件——指定控件形状设置-鸿蒙开发者社区

 <com.github.florent37.shapeofview.shapes.DottedEdgesCutCornerView
             ohos:layout_width="100dp"
             ohos:layout_height="match_parent"
             app:shape_dot_radius="3dp"
             app:shape_dot_spacing="2dp"
             app:shape_edge_position="right|left"
             app:shape_dottedEdgesCutCorner_bottomLeftSize="8dp"
             app:shape_dottedEdgesCutCorner_bottomRightSize="8dp"
             >

             <!-- YOUR CONTENT -->

 </com.github.florent37.shapeofview.shapes.DottedEdgesCutCornerView>

Animation

All shapes methods can be animated

For example, you can animate a RoundRect corner :鸿蒙开源组件——指定控件形状设置-鸿蒙开发者社区

 if (roundRect != null) {
            value = new AnimatorValue();
            value.setDuration(400L);  //动画持续时间
            value.setLoopedCount(Animator.INFINITE);  //动画无限次重复
            value.setCurveType(Animator.CurveType.LINEAR);
            value.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
                @Override
                public void onUpdate(AnimatorValue animatorValue, float v) {
                    roundRect.setBottomLeftRadius(getAnimatedValue(v, 200f, 0f));
                }
            });
            value.start();

  public static float getAnimatedValue(float fraction, float... values) {
        if (values == null || values.length == 0) {
            return 0;
        }
        if (values.length == 1) {
            return values[0] * fraction;
        } else {
            if (fraction == 1) {
                return values[values.length - 1];
            }
            float oneFraction = 1f / (values.length - 1);
            float offFraction = 0;
            for (int i = 0; i < values.length - 1; i++) {
                if (offFraction + oneFraction >= fraction) {
                    return values[i] + (fraction - offFraction) * (values.length - 1) * (values[i + 1] - values[i]);
                }
                offFraction += oneFraction;
            }
        }
        return 0;
    }

测试信息

CodeCheck代码测试无异常

CloudTest代码测试无异常

病毒安全检测通过

当前版本demo功能与原项目组件基本无差异

版本迭代

  • 1.0.0

版权和许可信息

Copyright 2017 Florent37, Inc.

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.

ShapeOfView-master.zip 12.9M 6次下载
已于2021-9-27 18:35:13修改
收藏
回复
举报
回复
    相关推荐