开发学院手机开发Android 开发 android自定义控件:可旋转View:可作为ImageView... 阅读

android自定义控件:可旋转View:可作为ImageView、ImageButton

 2010-05-14 16:58:00 来源:WEB开发网   
核心提示:43. mBackGroudDrawableId);44. mRotateDegrees=attrs.getAttributeFloatValue(namespace, "rotateDegrees",0.0f);45. }46.47. @Override48. protected void onD

43. mBackGroudDrawableId);

44. mRotateDegrees=attrs.getAttributeFloatValue(namespace, "rotateDegrees",0.0f);

45. }

46.

47. @Override

48. protected void onDraw(Canvas canvas) {

49. // TODO Auto-generated method stub

50. super.onDraw(canvas);

51. /**

52. * 旋转画布

53. */

54. if (mRotateDegrees==90.0f) {

55. canvas.rotate(mRotateDegrees, 0, 0);

56. canvas.translate(0, -mBackGroundHeight);

57. } else {

58. canvas.rotate(mRotateDegrees, mBackGroundWidth/2, mBackGroundHeight/2);

59. }

60. /**

61. * 执行draw

62. */

63. mBackGroudDrawable.setBounds(0, 0, mBackGroundWidth, mBackGroundHeight);

64. mBackGroudDrawable.draw(canvas);

65. }

66.

67. @Override

68. protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

69. // TODO Auto-generated method stub

70. super.onMeasure(widthMeasureSpec, heightMeasureSpec);

71. /**

72. * 设定View显示区域

73. */

74. mBackGroundHeight=mBackGroudDrawable.getMinimumHeight();

75. mBackGroundWidth=mBackGroudDrawable.getMinimumWidth();

76. if (mRotateDegrees==90.0f) {

77. setMeasuredDimension(mBackGroundHeight, mBackGroundWidth);

78. } else {

79. setMeasuredDimension(mBackGroundWidth, mBackGroundHeight);

80. }

81. }

82. }

/** * import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Log; import android.view.View; /** * @author Bill * @rotateDegrees 仅支持90.0 180.0 0.0(默认) * @background 图片资源文件 */ public class RotateableView extends View{ /** * 命名区域 */ private final String namespace =

上一页  1 2 3 4  下一页

Tags:android 定义 控件

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接