ot;
63 android:layout_weight="1"
64 android:orientation="horizontal" >
65
66 <RelativeLayout
67 android:layout_width="0dp"
68 android:layout_weight="1"
69 android:layout_height="match_parent" >
70
71 <com.chunk.customviewsdemo.views.ArcImageView.ArcImageView
72 android:id="@+id/aiv_three"
73 android:layout_width="match_parent"
74 android:layout_height="match_parent"
75 android:background="@drawable/cheese"
76 custom:drawStyle="RIGHT_TOP"
77 custom:drawStr="奶酪"
78 custom:arcAlpha="100"
79 custom:arcColor="@color/gray"
80 custom:textColor="@color/black"
81 custom:textSize="20sp" />
82 </RelativeLayout>
83
84 <RelativeLayout
85 android:layout_width="0dp"
86 android:layout_weight="1"
87 android:layout_height="match_parent" >
88
89 <com.chunk.customviewsdemo.views.ArcImageView.ArcImageView
90 android:id="@+id/aiv_four"
91 android:layout_width="match_parent"
92 android:layout_height="match_parent"
93 android:background="@drawable/barbecue"
94 custom:drawStyle="LEFT_TOP"
95 custom:drawStr="烧烤"
96 custom:arcAlpha="100"
97 custom:arcColor="@color/gray"
98 custom:textColor="@color/black"
99 custom:textSize="20sp" />
100
101 </RelativeLayout>
102 </LinearLayout>
103 </LinearLayout>
注意,在布局文件中引入自定义属性时需要加入一行代码:xmlns:custom="http://schemas.android.com/apk/res-auto"。
好了,需求搞定,剩下的就是搬到实际的项目当中去了。实现效果如下:
总结一下,自定义View一般就是通过重写onDraw、onMeasure()、onLayout()等方法来进行测量、绘制,绘制的时候一般会用到Canvas、Paint、Bitmap等类,测量和绘制的过程其实就是对现实生活中绘图工作的抽象和实现,我们利用面向对象的思想将画板、画纸、画笔等工具以及绘画的动作用一行行代码加以描述就OK啦!
由于实现过程比较简单,我就不贴源码了,大家如果对2D绘图还不是很了解,可以去搜一下相关资料或查阅相关书籍!
|