您的位置:首页 > 移动开发 > Android开发

android中实现自定义画线,画圆,画矩形,使用自定义字体

2013-09-01 13:50 501 查看
首先,新建xml文件,resource type为drawble,root element为shape

一、自定义画线
<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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: