Transparent and translucent Android surfaceview

Source: Internet
Author: User
Transparent // transparent translucent // translucent

Package RW. trans; import android. app. activity; import android. content. context; import android. graphics. bitmap; import android. graphics. bitmapfactory; import android. graphics. canvas; import android. graphics. pixelformat; import android. OS. bundle; import android. view. motionevent; import android. view. surfaceholder; import android. view. surfaceholder. callback; import android. view. surfaceview; public class transparentactivity extends activity {/** called when the activity is first created. */class mysurfaceview extends surfaceview implements callback {float left, top; Bitmap bitmap = bitmapfactory. decoderesource (getresources (), R. drawable. reen); Public mysurfaceview (context) {super (context); // todo auto-generated constructor stub getholder (). setformat (pixelformat. transparent); // set to transparent // getholder (). setformat (pixelformat. translucent); // translucent Getholder (). addcallback (this); setfocusable (true) ;}@ overridepublic void surfacechanged (surfaceholder holder, int format, int width, int height) {// todo auto-generated method stub} @ overridepublic void surfacecreated (surfaceholder holder) {// todo auto-generated method stub dodraw ();} private void dodraw () {// todo auto-generated method stubcanvas canvas = getholder (). lockcanvas (); canvas. drawbitmap (bitmap, left, top, null); getholder (). unlockcanvasandpost (canvas) ;}@ overridepublic void surfacedestroyed (surfaceholder holder) {// todo auto-generated method stub}/* (non-javadoc) * @ see android. app. activity # ontouchevent (Android. view. motionevent) * // @ overridepublic Boolean ontouchevent (motionevent event) {// todo auto-generated method stubleft = event. getx (); Top = event. gety (); dodraw (); return Super. ontouchevent (event) ;}@override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (New mysurfaceview (getapplicationcontext ()));}}

Androidmanifest. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Manifest xmlns: Android = "http://schemas.android.com/apk/res/android" package = "RW. trans "Android: versioncode =" 1 "Android: versionname =" 1.0 "> <uses-SDK Android: minsdkversion =" 10 "/>

Android: theme =" @ Android: style/theme. translucent "

<Intent-filter> <action Android: Name = "android. intent. action. main "/> <category Android: Name =" android. intent. category. launcher "/> </intent-filter> </activity>

</Application> </manifest>

 

 

Related Article

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.