Surfaceview transparent and translucent

Source: Internet
Author: User
  1. Transparent // transparent
  2. Translucent // translucent

  1.  
  2. Import Android. App. activity;
  3. Import Android. content. context;
  4. Import Android. Graphics. Bitmap;
  5. Import Android. Graphics. bitmapfactory;
  6. Import Android. Graphics. Canvas;
  7. Import Android. Graphics. pixelformat;
  8. Import Android. OS. Bundle;
  9. Import Android. View. motionevent;
  10. Import Android. View. surfaceholder;
  11. Import Android. View. surfaceholder. Callback;
  12. Import Android. View. surfaceview;
  13. Public class transparentactivity extends activity {
  14. /** Called when the activity is first created .*/
  15. Class mysurfaceview extends surfaceview implements callback {
  16. Float left, top;
  17. Bitmap bitmap = bitmapfactory. decoderesource (getresources (), R. drawable. reen );
  18. Public mysurfaceview (context ){
  19. Super (context );
  20. // Todo auto-generated constructor stub
  21. <Span style = "color: # ff0000;"> getholder (). setformat (pixelformat. Transparent); // set to transparent
  22. // Getholder (). setformat (pixelformat. translucent); // translucent
  23. Getholder (). addcallback (this );
  24. Setfocusable (true );
  25. }
  26. @ Override
  27. Public void surfacechanged (surfaceholder holder, int format, int width,
  28. Int height ){
  29. // Todo auto-generated method stub
  30. }
  31. @ Override
  32. Public void surfacecreated (surfaceholder holder ){
  33. // Todo auto-generated method stub
  34. Dodraw ();
  35. }
  36. Private void dodraw (){
  37. // Todo auto-generated method stub
  38. Canvas canvas = getholder (). lockcanvas ();
  39. Canvas. drawbitmap (bitmap, left, top, null );
  40. Getholder (). unlockcanvasandpost (canvas );
  41. }
  42. @ Override
  43. Public void surfacedestroyed (surfaceholder holder ){
  44. // Todo auto-generated method stub
  45. }
  46. /* (Non-javadoc)
  47. * @ See Android. App. Activity # ontouchevent (Android. View. motionevent)
  48. */
  49. @ Override
  50. Public Boolean ontouchevent (motionevent event ){
  51. // Todo auto-generated method stub
  52. Left = event. getx ();
  53. Top = event. Gety ();
  54. Dodraw ();
  55. Return super. ontouchevent (event );
  56. }
  57. }
  58. @ Override
  59. Public void oncreate (bundle savedinstancestate ){
  60. Super. oncreate (savedinstancestate );
  61. Setcontentview (New mysurfaceview (getapplicationcontext ()));
  62. }
  63. }

Androidmanifest. xml

 
  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Manifest xmlns: Android = "<a href =" http://schemas.android.com/apk/res/android "> http://schemas.android.com/apk/res/android </a>"
  3. Package = "RW. Trans"
  4. Android: versioncode = "1"
  5. Android: versionname = "1.0" type = "codeph" text = "/codeph">
  6. <Uses-SDK Android: minsdkversion = "10"/> <application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name">
  7. <Activity Android: Name = ". transparentactivity"
  8. Android: Label = "transparent surfaceview"
  9. Android: theme = "@ Android: style/theme. translucent"
  10. >
  11. <Intent-filter>
  12. <Action Android: Name = "android. Intent. Action. Main"/>
  13. <Category Android: Name = "android. Intent. Category. launcher"/>
  14. </Intent-filter>
  15. </Activity> </Application>
  16. </Manifest>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.