Skip to content

可自由设置Drawable大小的TextView,并且能让Drawable与Text一起居中显示(Esily set the Drawable size of the TextView, and let Drawable and Text display in center)

Notifications You must be signed in to change notification settings

FlodCoding/DrawableTextView

Repository files navigation

DrawableTextView

特性

  • 单独修改Drawable的宽度和高度
  • Drawable与文字一起居中显示
  • 文字在中心显示
  • 设置圆角

Demo

Download

截图



如何导入

根目录下的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" /> 

属性说明

XML

属性名 类型 默认值 说明
enableCenterDrawables boolean false 是否文字与Drawable一起居中显示
(仅当gravity水平或垂直居中有效)
enableTextInCenter boolean false 是否文字在中心显示
(当enableCenterDrawables=true生效时有效果)
radius dimension 0 设置四边的圆角(需要SDK_INT >= 21)

About

可自由设置Drawable大小的TextView,并且能让Drawable与Text一起居中显示(Esily set the Drawable size of the TextView, and let Drawable and Text display in center)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages