- 单独修改Drawable的宽度和高度
- Drawable与文字一起居中显示
- 文字在中心显示
- 设置圆角
根目录下的build.gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
App目录下的build.gradle
dependencies {
//需要Androidx
implementation 'com.github.FlodCoding:DrawableTextView:1.0.6'
}
drawableTextView.setEnableCenterDrawables(true)
.setEnableTextInCenter(true)
.setDrawableStart(DrawableStart, width, height) //设置Drawable 并定义其尺寸,单位是DP
.setRadiusDP(10) //设置圆角,单位dp,需要SDK_INT >= 21
...
<com.flod.view.DrawableTextView
android:id="@+id/dtv"
android:layout_width="300dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:background="@android:color/darker_gray"
android:drawableStart="@drawable/ic_face_black_24dp"
android:drawableTop="@drawable/ic_sentiment_satisfied_black_24dp"
android:gravity="center"
android:text="DrawableTextView"
android:textSize="20sp"
app:drawableStartHeight="50dp"
app:drawableStartWidth="50dp"
app:radius="10dp"
app:enableCenterDrawables="true"
app:enableTextInCenter="true" />
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
enableCenterDrawables | boolean | false | 是否文字与Drawable一起居中显示 (仅当gravity水平或垂直居中有效) |
enableTextInCenter | boolean | false | 是否文字在中心显示 (当enableCenterDrawables=true生效时有效果) |
radius | dimension | 0 | 设置四边的圆角(需要SDK_INT >= 21) |