搜索
您的当前位置:首页正文

Android xml 中绘制图形

来源:二三娱乐
<?xml version="1.0" encoding="utf-8"?>
<shape     
             android:shape="oval" >    
<solid android:color="#ff0000"/>    
<size  android:width="50dp"       
       android:height="50dp"/></shape>

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

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

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

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

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

Top