-
gradientContent
渐变色显示内容
- none不使用渐变色
- border边框使用渐变色
- label标签文字使用渐变色
- labelBackground标签背景使用渐变色
- all边框及标签背景使用渐变色
-
type
渐变色类型
- linear线性渐变色
- radial径向渐变色
- sweep扫描渐变
-
startColor
渐变色起始颜色
-
centerColor
渐变色中间颜色
-
endColor
渐变色结束颜色
-
orientation
使用线性渐变时,渐变方向,水平方向(horizontal)或垂直方向(vertical)
-
borderWidth
边框线的宽度,默认对最大宽度做了限制,不超过宽与高的最小尺寸值的四分之一
-
borderColor
边框线的颜色,默认值为"#8A2BE2"
-
displayBorder
显示边框线,默认不显示(false),显示则为(true)
-
radius
圆角矩形圆弧半径,默认为"0",如果设置大于"0", 则设置(topLeftRadius、topRightRadius、bottomLeftRadius、bottomRightRadius)属性会失效
-
topLeftRadius(左上角圆弧半径)
bottomLeftRadius(左下角圆弧半径)
topRightRadius(右上角圆弧半径)
bottomRightRadius(右下角圆弧半径)矩形四角的圆弧半径,默认为"0",如果设置"radius"属性时,则此属性值会取"radius"设置的值
-
displayType
显示类型,默认为矩形(normal)。
- normal矩形显示
- circle圆形显示
- round_rect圆角矩形显示
-
displayLabel
是否显示标签,默认不显示标签(false),显示为(true)
-
labelBackground
标签背景色,默认值为"#9FFF0000"
-
labelWidth
标签宽度,单位(dp)
-
startMargin
距离开始位置间距,单位(dp)
-
text
标签文本
-
textColor
标签文本颜色
-
textSize
标签文本文字大小
-
labelGravity
标签显示位置(默认在右上角)
- leftTop左上角显示
- rightTop右上角显示
- leftBottom左下角显示
- leftBottom右下角显示
-
typeface
标签文字字体
- normal默认字体类型
- sans默认的sans字体
- serif默认的serifs字体
- monospace默认的monospace字体
-
textStyle
字体样式
- normal正常字体
- bold粗体
- italic斜体
-
从assets目录加载字体
Typeface typeface = Typeface.createFromAsset(getAssets(), "assets目录下的字体文件(注意带文件后缀, *.ttf)"); roundImageView.setTypeface(typeface);
-
从文件中加载字体
Typeface typeface = Typeface.createFromFile(new File("字体文件路径(注意后缀 *.ttf)")); 或 Typeface typeface = Typeface.createFromFile("字体文件路径(注意后缀 *.ttf)"); roundImageView.setTypeface(typeface);
-
更多查看Typeface类
-
1. 在项目的build.gradle中(非app/build.gradle)添加"maven { url 'https://jitpack.io' }"
allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
2. 在app/build.gradle中添加"implementation 'com.github.xuxuliooo:RoundImageView:1.1.2'"
dependencies { ... implementation 'com.github.xuxuliooo:RoundImageView:1.1.2' }
-
直接在app/build.gradle中添加"implementation 'com.cbman:roundimageview:1.1.2'"
dependencies { ... implementation 'com.cbman:roundimageview:1.1.2' }
-
圆角矩形使用方式
-
自定义四角圆弧半径的大小
<com.cbman.roundimageview.RoundImageView android:layout_width="100dp" android:layout_height="100dp" android:scaleType="center" android:src="@drawable/img" android:bottomLeftRadius="30dp" android:topLeftRadius="10dp" android:bottomRightRadius="20dp" android:topRightRadius="15dp" app:borderColor="#ff0000" app:borderWidth="3dp" app:displayBorder="true" app:displayType="round_rect" />
-
四角圆弧半径相同时直接使用下面方式即可
<com.cbman.roundimageview.RoundImageView android:layout_width="100dp" android:layout_height="100dp" android:scaleType="center" android:src="@drawable/img" android:radius="20dp" app:borderWidth="1dp" app:displayType="round_rect" />
-
-
圆形使用方式
<com.cbman.roundimageview.RoundImageView android:layout_width="100dp" android:layout_height="wrap_content" android:scaleType="center" android:src="@drawable/img" app:borderWidth="1dp" app:displayType="circle" />
-
矩形使用方式
<com.cbman.roundimageview.RoundImageView android:layout_width="100dp" android:layout_height="100dp" android:scaleType="center" android:src="@drawable/img" app:borderWidth="1dp" app:displayType="normal" />
-
矩形带标签使用方式
<com.cbman.roundimageview.RoundImageView android:layout_width="100dp" android:layout_height="100dp" android:scaleType="center" android:src="@drawable/img" android:text="标签文本" android:textSize="12sp" android:textColor="@android:color/white" android:typeface="normal" android:textStyle="italic" app:displayLabel="true" app:labelGravity="rightTop" app:labelWidth="20dp" app:startMargin="60dp" app:labelBackground="@color/colorAccent" app:borderWidth="1dp" app:displayType="normal" />
-
边框渐变色使用方式
<com.cbman.roundimageview.RoundImageView android:id="@+id/r6" android:layout_width="100dp" android:layout_height="100dp" android:layout_below="@id/r4" android:layout_alignStart="@id/r4" android:layout_alignLeft="@id/r4" android:layout_marginTop="15dp" android:endColor="@color/colorPrimaryDark" android:orientation="vertical" android:scaleType="center" android:src="@drawable/img" android:startColor="@color/colorAccent" android:type="linear" app:borderWidth="5dp" app:displayBorder="true" app:displayType="circle" app:gradientContent="border" />
Copyright 2020 Bo Chen
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.