RCLayout(圓角布局)
膜拜大神:https://github.com/GcsSloop/rclayout
Android 通用圓角布局,快速實(shí)現(xiàn)圓角需求。
之前做項(xiàng)目的時(shí)候有圓角相關(guān)需求,在網(wǎng)上找了很多方案都不夠滿意,于是自己做了一個(gè),目前已經(jīng)使用了一段時(shí)間,更新了多個(gè)版本,我遇到的問題都進(jìn)行了修復(fù),并且添加了很多方便的可配置屬性,以滿足不同需求。
效果預(yù)覽

006tKfTcly1fk7twywj5oj30u01fewka.jpg
支持的特性
- [x] 包裹任意組件。
- [x] 設(shè)置圓角大小。
- [x] 分別對(duì)每一個(gè)角設(shè)置圓角大小。
- [x] 設(shè)置描邊寬度。
- [x] 設(shè)置描邊顏色。
- [x] 圓形。
- [x] 支持Padding。
- [x] 圓角抗鋸齒。
- [x] 內(nèi)容可點(diǎn)擊區(qū)域即為顯示區(qū)域。
主要文件
| 名字 | 摘要 |
|---|---|
| RCRealtiveLayout | 圓角相對(duì)布局 |
1. 基本用法
RCRelativeLayout(Round Corner RelativeLayout),使用圓角布局包裹需要圓角的內(nèi)容然后添加自定義屬性即可
<com.gcssloop.widget.RCRelativeLayout
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:round_corner="40dp">
<!--任意View-->
<ImageView
android:scaleType="centerCrop"
android:src="@drawable/test"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#aaffffff"
android:gravity="center"
android:layout_alignParentBottom="true"
android:text="圓角測(cè)試"/>
</com.gcssloop.widget.RCRelativeLayout>
2. 配置屬性
可以在布局文件中配置的屬性如下:
| 屬性名稱 | 摘要 | 是否必須設(shè)置 | 類型 |
|---|---|---|---|
| round_corner | 總體圓角半徑 | 否 | dp |
| round_corner_top_left | 左上角圓角半徑 | 否 | dp |
| round_corner_top_right | 右上角圓角半徑 | 否 | dp |
| round_corner_bottom_left | 左下角圓角半徑 | 否 | dp |
| round_corner_bottom_right | 右下角圓角半徑 | 否 | dp |
| round_as_circle | 是否剪裁為圓形 | 否 | boolean |
| stroke_width | 描邊半徑 | 否 | dp |
| stroke_color | 描邊顏色 | 否 | color |
3. 屬性簡(jiǎn)介
3.1 圓角屬性
round_as_circle 的權(quán)限最高,在默認(rèn)情況下它的值為false,如果設(shè)置這個(gè)屬性為 true,則會(huì)忽略圓角大小的數(shù)值,剪裁結(jié)果均為圓形。
設(shè)置圓角大小的一共有5個(gè)屬性,一個(gè)是全局的圓角大小round_corner,其余四個(gè)round_corner_xx_xx是分別對(duì)每一個(gè)角進(jìn)行設(shè)置,它們之間存在替代關(guān)系。
- 僅設(shè)置全局,所有的角都跟隨全局。
- 僅對(duì)某些角設(shè)置,則只有設(shè)置過的角會(huì)有圓角效果。
- 全局和部分都有設(shè)置,則有具體設(shè)置的角跟隨具體設(shè)置的數(shù)值,沒有具體設(shè)置的角跟隨全局設(shè)置。
3.2 描邊屬性
描邊寬度stroke_width默認(rèn)情況下數(shù)值為 0,即不存在描邊效果。
描邊顏色stroke_color默認(rèn)情況下為白色,允許自定義顏色。
4.添加方法
4.1 添加倉(cāng)庫(kù)
在項(xiàng)目的 build.gradle 文件中配置倉(cāng)庫(kù)地址。
allprojects {
repositories {
jcenter()
// 私有倉(cāng)庫(kù)地址
maven { url "http://lib.gcssloop.com/repository/gcssloop-central/" }
}
}
4.2 添加項(xiàng)目依賴
在需要添加依賴的 Module 下添加以下信息,使用方式和普通的遠(yuǎn)程倉(cāng)庫(kù)一樣。
compile 'com.gcssloop.widget:rclayout:1.4.2@aar'