6 Star 0 Fork 0

hihopeorg / ohos-percent-support-extend

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 5.91 KB
一键复制 编辑 原始数据 按行查看 历史
haoxuchao 提交于 2021-09-15 16:03 . Optimize the code

ohos-percent-support-extend

本项目是基于开源项目percent-support-extends进行ohos化的移植和开发的,可以通过项目标签以及github地址(https://github.com/hongyangAndroid/android-percent-support-extend )追踪到原项目版本

项目介绍

  • 项目名称:ohos-percent-support-extend

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

  • 功能:PercentLinearLayout、PercentRelativeLayout、PercentFrameLayout布局,支持宽度高度百分比设置值、支持margin百分比设置值 、支持padding百分比设置值、支持minWidth , maxWidth , minHeight , maxHeight百分比设置值、支持TextView、Button、EditText的textSize 、支持ScrollView内部为Linearlayout、支持任何View的尺寸参照屏幕的宽或者高

  • 项目移植状态:完成

  • 调用差异:无

  • 项目作者和维护人:hihope

  • 联系方式:hihope@hoperun.com

  • 原项目Doc地址:https://github.com/hongyangAndroid/android-percent-support-extend

  • 原项目基线版本:1.1.1, sha1: 87a2fed084cf6b6b8adc26134215d11a5fbb36bf

  • 编程语言:Java

  • 外部库依赖:无

效果展示

gif

安装教程

方法1.

  1. 编译har包:library.har。
  2. 启动 DevEco Studio,将编译的har包,导入工程目录“entry->libs”下。
  3. 在moudle级别下的build.gradle文件中添加依赖,在dependences标签中增加对libs目录下har包的引用。
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
}
  1. 在导入的har包上点击右键,选择“Add as Library”对包进行引用,选择需要引用的模块,并点击“OK”即引用成功。

方法2.

  1. 在工程的build.gradle的allprojects中,添加HAR所在的Maven仓地址
repositories {
    maven {
        url 'http://106.15.92.248:8081/repository/Releases/'
    }
}
  1. 在应用模块的build.gradle的dependencies闭包中,添加如下代码:
dependencies {
    implementation 'com.zhy.ohos:percent-support-extend:1.0.0'
}

使用说明

1. 布局文件定义中使用自定义控件:

com.zhy.ohos.percent.support.PercentLinearLayout com.zhy.ohos.percent.support.PercentRelativeLayout com.zhy.ohos.percent.support.PercentFrameLayout

        <?xml version="1.0" encoding="utf-8"?>
        <com.zhy.ohos.percent.support.PercentFrameLayout
            xmlns:ohos="http://schemas.huawei.com/res/ohos"
            xmlns:app="http://schemas.huawei.com/apk/res/ohos"
            ohos:id="$+id:percentFrameLayout"
            ohos:height="match_parent"
            ohos:width="match_parent"
            ohos:orientation="vertical">
        
            <Text
                ohos:height="0vp"
                ohos:width="0vp"
                ohos:background_element="#ff44aacc"
                ohos:layout_alignment="center"
                app:layout_heightPercent="50%w"
                app:layout_marginLeftPercent="25%"
                app:layout_marginTopPercent="35%"
                app:layout_widthPercent="50%w"/>
            ……
        </com.zhy.ohos.percent.support.PercentFrameLayout>
 
        <com.zhy.ohos.percent.support.PercentRelativeLayout
            xmlns:ohos="http://schemas.huawei.com/res/ohos"
            xmlns:app="http://schemas.huawei.com/apk/res/ohos"
            ohos:height="match_parent"
            ohos:width="match_parent">

            <Component
                ohos:id="$+id:top_left"
                ohos:height="0vp"
                ohos:width="match_parent"
                ohos:background_element="#ff44aacc"
                app:layout_heightPercent="33%"
                app:layout_widthPercent="100%"/>

            <Component
                ohos:id="$+id:top_right"
                ohos:height="0vp"
                ohos:width="match_parent"
                ohos:background_element="#ffe40000"
                ohos:below="$id:top_left"
                app:layout_heightPercent="33%"
                app:layout_widthPercent="100%"
                app:layout_marginTopPercent="33%"/>
                ……
        </com.zhy.ohos.percent.support.PercentRelativeLayout>

        <com.zhy.ohos.percent.support.PercentLinearLayout
            xmlns:ohos="http://schemas.huawei.com/res/ohos"
            xmlns:app="http://schemas.huawei.com/apk/res/ohos"
            ohos:id="$+id:percentLinearLayout"
            ohos:height="match_parent"
            ohos:width="match_parent"
            ohos:orientation="vertical"
         >

            <Text
                ohos:height="0vp"
                ohos:width="0vp"
                ohos:background_element="#ff44aacc"
                ohos:text="width:60%,height:5%,ts:0.9%"
                ohos:text_color="#ffffff"
                app:layout_heightPercent="5%"
                app:layout_textSizePercent="0.9%"
                app:layout_widthPercent="60%w"/>
        </com.zhy.ohos.percent.support.PercentLinearLayout>

2. 支持百分比指定特定的参考值,比如宽度或者高度。

   例如:
   app:layout_heightPercent="50%w"
   app:layout_marginPercent="15%w"
   app:layout_marginBottomPercent="20%h"

3. 支持通过app:layout_textSizePercent设置textView(button,editText)的textSize

   例如:
    <Text
         app:layout_textSizePercent="3%h"
    />

4. 支持minWidth,maxWidth,minHeight,maxHeight的支持。

   例如:
   app:layout_maxWidthPercent
   app:layout_maxHeightPercent
   app:layout_minWidthPercent
   app:layout_minWidthPercent

5. 支持padding百分比设置值

   例如:
   app:layout_paddingBottomPercent="8%w"
   app:layout_paddingLeftPercent="2%w"
   app:layout_paddingRightPercent="4%w"
   app:layout_paddingTopPercent="6%w"

6. 支持任何尺寸参考屏幕的宽或者高

   <Image
     //...
      app:layout_heightPercent="30%sh"
      app:layout_widthPercent="30%sh"/>

版本迭代

  • 1.0.0

版权和许可信息

Apache license version 2.0

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hihopeorg/ohos-percent-support-extend.git
git@gitee.com:hihopeorg/ohos-percent-support-extend.git
hihopeorg
ohos-percent-support-extend
ohos-percent-support-extend
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891