1 Star 1 Fork 3

CHINASOFT_OHOS / labelview

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 6.25 KB
一键复制 编辑 原始数据 按行查看 历史
JiangJun 提交于 2021-08-20 09:37 . 【修改内容】:hapm gif

labelview

项目介绍

  • 项目名称:labeView

  • 所属系列:openharmony的第三方组件适配移植

  • 功能:在按钮 文字 图片上添加角标。

  • 项目移植状态:完成

  • 调用差异:无

  • 开发版本:sdk6,DevEco Studio 2.2 Beta1

  • 基线版本:Release v1.1.2

效果演示

输入图片说明

安装教程

1.在项目根目录下的build.gradle文件中,

allprojects {
    repositories {
        maven {
            url 'https://s01.oss.sonatype.org/content/repositories/releases/'
        }
    }
}

2.在entry模块的build.gradle文件中,

dependencies {
   implementation('com.gitee.chinasoft_ohos:labelview:1.0.0')
   ......  
}

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

使用说明

将xml代码放入布局中,如下所示:

LabelButtonView
<com.lid.lib.LabelButtonView
          ohos:height="48vp"
          ohos:width="200vp"
          ohos:background_element="#03a9f4"
          ohos:text="Button"
          ohos:text_color="#ffffff"
          ohos:text_size="14vp"
          app:label_backgroundColor="#C2185B"
          app:label_distance="50"
          app:label_height="70"
          app:label_orientation="2"
          app:label_text="HD"
          app:label_textSize="30"
          app:label_textStyle="0"/>
LabelImageView
<com.lid.lib.LabelImageView
              ohos:height="280vp"
              ohos:width="0vp"
              ohos:weight="1"
              ohos:background_element="#fff"
              ohos:image_src="$media:image1"
              ohos:scale_mode="clip_center"
              app:label_backgroundColor="#C2185B"
              app:label_distance="125"
              app:label_orientation="1"
              app:label_height="90"
              app:label_text="CHINA"
              app:label_textSize="40"
              app:label_textStyle="2"/>
LabelTextView
<com.lid.lib.LabelTextView
          ohos:height="48vp"
          ohos:width="100vp"
          ohos:background_element="#212121"
          ohos:layout_alignment="horizontal_center"
          ohos:text="TextView"
          ohos:text_size="14vp"
          ohos:text_alignment="center"
          ohos:text_color="#ffffff"
          ohos:top_margin="8vp"
          app:label_backgroundColor="#C2185B"
          app:label_distance="50"
          app:label_orientation="1"
          app:label_height="60"
          app:label_text="POP"
          app:label_textSize="27"
          app:label_textStyle="2"/>
如果在自定义视图中需要标签:
1. 创建一个新的视图类扩展' YourView '
2. 使用LabelViewHelper作为你的成员对象
3. 在构造函数和onDraw函数中调用LabelViewHelper方法
4. 在其他函数中调用LabelViewHelper方法
public class LabelXXXView extends YourView implements Component.DrawTask {
  LabelViewHelper utils;
  public LabelXXXView(Context context) {
      this(context, null);
  }
  public LabelXXXView(Context context, AttributeSet attrs) {
      this(context, attrs, 0);
  }
  public LabelXXXView(Context context, AttributeSet attrs, int defStyleAttr) {
      super(context, attrs, defStyleAttr);
      utils = new LabelViewHelper(context, attrs, defStyleAttr);
  }
  @Override
  protected void onDraw(Canvas canvas) {
              utils.onDraw(canvas, getWidth() - getPaddingLeft() - getPaddingRight(), getHeight() - getPaddingTop() - getPaddingBottom());

  }
  public void setLabelHeight(int height) {
      utils.setLabelHeight(this, height);
  }

  public int getLabelHeight() {
      return utils.getLabelHeight();
  }

  public void setLabelDistance(int distance) {
      utils.setLabelDistance(this, distance);
  }

  public int getLabelDistance() {
      return utils.getLabelDistance();
  }

  public boolean isLabelVisual() {
      return utils.isLabelVisual();
  }

  public void setLabelVisual(boolean isEnable) {
      utils.setLabelVisual(this, isEnable);
  }

  public int getLabelOrientation() {
      return utils.getLabelOrientation();
  }

  public void setLabelOrientation(int orientation) {
      utils.setLabelOrientation(this, orientation);
  }

  public Color getLabelTextColor() {
      return utils.getLabelTextColor();
  }

  public void setLabelTextColor(Color textColor) {
      utils.setLabelTextColor(this, textColor);
  }

  public Color getLabelBackgroundColor() {
      return utils.getLabelBackgroundColor();
  }

  public void setLabelBackgroundColor(Color backgroundColor) {
      utils.setLabelBackgroundColor(this, backgroundColor);
  }

  public String getLabelText() {
      return utils.getLabelText();
  }

  public void setLabelText(String text) {
      utils.setLabelText(this, text);
  }

  public int getLabelTextSize() {
      return utils.getLabelTextSize();
  }

  public void setLabelTextSize(int textSize) {
      utils.setLabelTextSize(this, textSize);
  }

  public int getLabelTextStyle() {
      return utils.getLabelTextStyle();
  }

  public void setLabelTextStyle(int textStyle) {
      utils.setLabelTextStyle(this, textStyle);
  }
}

测试信息

CodeCheck代码测试无异常

CloudTest代码测试无异常

病毒安全检测通过

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

版本迭代

  • 1.0.0

版权和许可信息

Copyright 2014 linger1216

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.
Java
1
https://gitee.com/chinasoft_ohos/labelview.git
git@gitee.com:chinasoft_ohos/labelview.git
chinasoft_ohos
labelview
labelview
master

搜索帮助