画圆,画直线总结

今天遇到一个这样的需求,就是要在item左边画一个空心圆,圆的上方有一条直线,下面也有一条直线的,问美工那边要图片,等了好久都没回应,无奈之下,试着自己写一个xml文件来实现吧,后期有图片再加上去

画空心圆:思路是在Image控件里面,src部分指定一个xml文件当做内圆,background部分指定另一个xml文件当做外圆,padding设置成想要的宽度,相当于圆圈厚度

<ImageView 
             android:layout_height="15dp"
             android:layout_width="15dp"
             android:background="@drawable/round_out_shape"
             android:src="@drawable/round_in_shape"
             android:padding="2dp"/>

round_out_shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >
    <solid android:color="#CCCCCC" />
</shape>

round_in_shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >
    <solid android:color="#f0f0f0" />
</shape>

效果

关于画直线,其实是一个rectangle,当宽度或高度很小的时候,看起来就像一条直线了


你可能感兴趣的:(画圆,画直线总结)