首先介绍一下功能:点击人体部位实现微交互,并进行页面跳转。
此功能共有三类人,男人女人和小孩,同时又结合了前身,后背,及头部放大,故有3*3种情况,这里我们使用自定义View去解决。
首先我们自定义一个BodyView继承于View。
<ol><li><span style="font-family:Microsoft YaHei;font-size:12px;"> public BodyView(Context context) {</span></li><li><span style="font-family:Microsoft YaHei;font-size:12px;"> this(context, null);</span></li><li><span style="font-family:Microsoft YaHei;font-size:12px;"> }</span></li><li><span style="font-family:Microsoft YaHei;font-size:12px;">
</span></li><li><span style="font-family:Microsoft YaHei;font-size:12px;"> public BodyView(Context context, AttributeSet paramAttributeSet) {</span></li><li><span style="font-family:Microsoft YaHei;font-size:12px;"> this(context, paramAttributeSet, 0);</span></li><li><span style="font-family:Microsoft YaHei;font-size:12px;"> }</span></li><li><span style="font-family:Microsoft YaHei;font-size:12px;">
</span></li><li><span style="font-family:Microsoft YaHei;font-size:12px;"> public BodyView(Context context, AttributeSet paramAttributeSet, int paramInt) {</span></li><li><span style="font-family:Microsoft YaHei;font-size:12px;"> super(context, paramAttributeSet, paramInt);</span></li><li><span style="font-family:Microsoft YaHei;font-size:12px;"> this.mContext = context;</span></li><li><span style="font-family:Microsoft YaHei;font-size:12px;"> init();</span></li><li><span style="font-family:Microsoft YaHei;font-size:12px;"> }</span></li></ol>
一、首先我们在init()方法中做一些初始化
<ol><li><span style="font-family: 'Microsoft YaHei';"> </span><span style="font-family: 'Microsoft YaHei';">private void init() {</span></li><li><span style="font-family: 'Microsoft YaHei';"> float density = getResources().getDisplayMetrics().density;</span></li><li><span style="font-family: 'Microsoft YaHei';"> BitmapFactory.Options localOptions = new BitmapFactory.Options();</span></li><li><span style="font-family: 'Microsoft YaHei';"> localOptions.inJustDecodeBounds = true;</span></li><li><span style="font-family: 'Microsoft YaHei';"> BitmapFactory.decodeResource(getResources(), R.mipmap.man_front, localOptions);</span></li><li><span style="font-family: 'Microsoft YaHei';"> mManFrontWidth = ((int) (density * localOptions.outWidth / 2.0F));</span></li><li><span style="font-family: 'Microsoft YaHei';"> mManFrontHeight = ((int) (density * localOptions.outHeight / 2.0F));</span></li><li><span style="font-family: 'Microsoft YaHei';"> BitmapFactory.decodeResource(getResources(), R.mipmap.man_bigface, localOptions);</span></li><li><span style="font-family: 'Microsoft YaHei';"> mHeadWidth = ((int) (density * localOptions.outWidth / 2.0F));</span></li><li><span style="font-family: 'Microsoft YaHei';"> mHeadHeight = ((int) (density * localOptions.outHeight / 2.0F));</span></li><li><span style="font-family: 'Microsoft YaHei';"> mPaint = new Paint();</span></li><li><span style="font-family: 'Microsoft YaHei';"> mPaint.setAntiAlias(true);</span></li><li><span style="font-family: 'Microsoft YaHei';"> mPaint.setColor(Color.WHITE);</span></li><li><span style="font-family: 'Microsoft YaHei';"> mPaint.setStrokeWidth(5.0F);</span></li><li><span style="font-family: 'Microsoft YaHei';"> mInitAreaRunnable = new InitAreaRunnable(this);</span></li><li><span style="font-family: 'Microsoft YaHei';"> }</span></li></ol>
我们做的是drawBitmap,这里是对