Android xml 中绘制图形

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"    
             android:shape="oval" >    
<solid android:color="#ff0000"/>    
<size  android:width="50dp"       
       android:height="50dp"/></shape>

<h3>布局xml文件中使用imageview控件

<h2>(2)绘制直线<h2>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line" >
    <stroke android:width="1dp"  //线的粗度
        android:color="#ff0000"  //颜色
        android:dashWidth="2dp"  //虚线的线段长度
        android:dashGap="3dp"/>  //虚线的间隔长度
</shape>

<h2>(3)绘制矩形<h2>

<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>

<h2>(4)使用自定义字体<h2>

TextView textView = (TextView) findViewById(R.id.textView2);
Typeface tf = Typeface.createFromAsset(getAssets(), 
"fonts/samplefont.ttf");
//读取****字体****textView.setTypeface(tf);//设置****字体****

<h6>把****字体****格式文件.ttf,拷贝到assets目录下,读取****字体****文件Typeface.createFromAsset,设置类型setTypeface<h6>

<h6>转自http://webcache.googleusercontent.com/search?q=cache:eyY6eiAW9DkJ:wei.l.o.v.e.blog.163.com/blog/static/1162853472014339167799/+&cd=1&hl=zh-CN&ct=clnk&gl=cn<h6>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容