android中实现自定义画线,画圆,画矩形,使用自定义字体
2013-09-01 13:50
501 查看
首先,新建xml文件,resource type为drawble,root element为shape
一、自定义画线
布局xml文件中可以使用textview控件,设置背景属性
二、自定义画圆
布局xml文件中使用imageview控件
三、自定义画矩形
四、使用自定义字体
把字体格式文件.ttf,拷贝到assets目录下,读取字体文件Typeface.createFromAsset,设置类型setTypeface
代码中使用字体如下:
本文出自 “wangcuijing” 博客,请务必保留此出处http://wangcuijing.blog.51cto.com/7233352/1286598
一、自定义画线
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line" > <stroke android:width="1dp" //线的粗度 android:color="#33ccff" //颜色 android:dashWidth="2dp" //虚线的线段长度 android:dashGap="5dp"/> //虚线的间隔长度 </shape>
布局xml文件中可以使用textview控件,设置背景属性
二、自定义画圆
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <solid android:color="#33ccff"/> <size android:width="50dp" //圆或椭圆 android:height="50dp"/> </shape>
布局xml文件中使用imageview控件
三、自定义画矩形
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient android:angle="45" //渐变角度 45的整数倍 android:centerColor="#00ff00" //渐变颜色 android:endColor="#0000ff" android:startColor="#ff0000" /> <solid android:color="#33ccff" /> //纯色 <size android:height="100dp" android:width="50dp" /> <corners android:radius="10dp" /> //圆角 </shape>
四、使用自定义字体
把字体格式文件.ttf,拷贝到assets目录下,读取字体文件Typeface.createFromAsset,设置类型setTypeface
代码中使用字体如下:
TextView textView = (TextView) findViewById(R.id.textView2); Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/samplefont.ttf");//读取字体 textView.setTypeface(tf);//设置字体
本文出自 “wangcuijing” 博客,请务必保留此出处http://wangcuijing.blog.51cto.com/7233352/1286598
相关文章推荐
- Android APP使用自定义字体实现方法
- 解析Android中使用自定义字体的实现方法
- 在android里面使用自定义字体
- Android 中使用自定义字体的方法
- Android 开发使用自定义字体
- android圆角矩形图片的实现进而讨论view自定义的要点
- Android 中使用自定义字体的方法
- Android中自定义MultipartEntity实现文件上传以及使用Volley库实现文件上传
- Android 使用自定义字体
- Delphi XE5开发Android程序使用自定义字体文件.
- Android提高篇之自定义dialog实现processDialog“正在加载”效果、使用Animation实现图片旋转
- Android中自定义MultipartEntity实现文件上传以及使用Volley库实现文件上传
- Android使用ScrollView和自定义的ListView实现两列的ListView
- Android使用自定义View继承SurfaceView实现动态折线图的绘制
- Android中Spinner下拉列表(使用ArrayAdapter和自定义Adapter实现)
- Android种使用Notification实现通知管理以及自定义通知栏实例(示例四)
- Android中使用自定义的VideoController和MediaPlayer实现视频的窗口和全屏播放
- Android 使用自定义RecyclerView控件实现Gallery效果
- android progressbar 使用自定义图片时的左右两端圆角效果实现
- android 开发零起步学习笔记(十七):自定义android用户控件,使用回调函数实现自定义事件