Android 自定义组件学习 3

         可能是我继承的类有问题吧...不过重新做了一个继承View的,而且对整个画布进行旋转,效果是图片旋转了,但局限于canvas上View限定的区域,图片不能完全显示,而且还要重写其监听事件。
  这是代码:旋转整个canvas 
public RotateView(Context context, AttributeSet attrs) {
         super(context, attrs);
// TODO Auto-generated constructor stub
       mBackGroudDrawableId=attrs.getAttributeResourceValue(namespace, "background",R.drawable.qq);
      mBackGroudDrawable = context.getResources().getDrawable(mBackGroudDrawableId);
       mRotateDegrees=attrs.getAttributeFloatValue(namespace, "rotateDegrees",0.0f);
}
@Override
           protected void onDraw(Canvas canvas) {
                         super.onDraw(canvas);
                                     if (mRotateDegrees==90.0f) {
                                           canvas.rotate(mRotateDegrees, 0, 0);
                                           canvas.translate(0, -mBackGroundHeight);
                                          }else{
                                           canvas.rotate(mRotateDegrees, mBackGroundWidth/2, mBackGroundHeight/2);
}
                                             mBackGroudDrawable.setBounds(0, 0, mBackGroundWidth, mBackGroundHeight);
                                             mBackGroudDrawable.draw(canvas);
}
@Override
                                    protected void onMeasure(int widthMeasureSpec,int heightMeasureSpec){
                                                   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                                                    mBackGroundHeight=mBackGroudDrawable.getMinimumHeight();
                                                   mBackGroundWidth=mBackGroudDrawable.getMinimumWidth();

                                                     if (mRotateDegrees==90.0f) {
                                                               setMeasuredDimension(mBackGroundHeight, mBackGroundWidth);
                                                    }else{
                                                           setMeasuredDimension(mBackGroundWidth, mBackGroundHeight);
}


}

但效果是:  
  那我想知道有没有一种方法,可以使Button旋转,当我单击叠加在一起的Button中某一个Button时(触发的是该Button未被其他Button覆盖的部分),能够响应我所设定事件,并且我要在每个Button上加载我喜欢的背景图片。
  上述,也许只是其中方法的一种(对整个ImageButton旋转),还有一种就是计算每张叠加图片的位置区域,通过一个判断比较的过程来设置响应事件,这种方法比较麻烦,暂时不予考虑.
  希望各位热爱Android的童鞋,可以给我小小的建议....小弟真的不胜感激!!!!!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值