Android中自定义TextView的形状--圆形-椭圆形-圆角矩形-线条
16lz
2021-12-04
基本步骤:
在drawable文件夹下建立一个shape.xml
在drawable文件夹下建立一个shape.xml
shape.xml:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#FF8C2E"/> <corners android:radius="360dip"/> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" />shape>
在主界面中的main.xml:
android:layout_width="125dp"
android:layout_height="50dp"
android:background="@drawable/shape"
/>
注意:在shape文件中,
表示绘制椭圆:
android:shape="oval"
表示绘制线条:
android:shape="line"
表示圆形:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="@color/colorAccent"/> <corners android:radius="180dip"/> <padding android:left="5dp" android:top="10dp" android:right="5dp" 根据字数多少 大小 边距稍微调一下就能出来 android:bottom="10dp" />shape>
表示绘制矩形;加上半径,则可以绘制圆角矩形。
android:shape="rectangle"
更多相关文章
- Android开发历程之三
- Android(安卓)shape 绘制图形的实例详解
- Android(安卓)OpenGL ES基础教程
- Android百度地图开发(三)范围搜索
- 动态绘制CheckedTextView
- android 随手记-画虚线
- Android自定义视图二:用Canvas和Paint绘制折线图
- Android_VectorDrawable矢量图与SVG
- Android实现书籍翻页效果--扩展版