分享

Android设置SurfaceView任意大小和任意位置

 mediatv 2017-03-26



目录(?)[+]

1. 代码

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1.    public void init() {  
  2.          
  3.        // FrameLayout  
  4.        ViewGroup.LayoutParams framelayout_params =  
  5.            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,  
  6.                                       ViewGroup.LayoutParams.MATCH_PARENT);  
  7.        mFrameLayout = new FrameLayout(this);  
  8.        mFrameLayout.setLayoutParams(framelayout_params);  
  9.   
  10.        // Cocos2dxEditText layout  
  11.        ViewGroup.LayoutParams edittext_layout_params =  
  12.            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,  
  13.                                       ViewGroup.LayoutParams.WRAP_CONTENT);  
  14.        Cocos2dxEditText edittext = new Cocos2dxEditText(this);  
  15.        edittext.setLayoutParams(edittext_layout_params);  
  16.   
  17.        // ...add to FrameLayout  
  18.        mFrameLayout.addView(edittext);  
  19.   
  20.        //////////////////////////////////////////  
  21. // Added by Myarrow on 2014-10-28 start  
  22. // Create SurfaceView for MediaPlayer  
  23.        mMediaPlayView = new SurfaceView(this);    
  24.        //mMediaPlayView.setBackgroundResource(cn.xx.yy.R.drawable.videostart);  
  25.        mFrameLayout.addView(mMediaPlayView);          
  26.   
  27.        // Create SurfaceView for camera preview  
  28.        mCameraView = new SurfaceView(this);  
  29.        mCameraView.setZOrderOnTop(true);  
  30.        FrameLayout.LayoutParams cameraFL = new FrameLayout.LayoutParams(320240,Gravity.TOP); // set size  
  31.        cameraFL.setMargins(9005000);  // set position  
  32.        mCameraView.setLayoutParams(cameraFL);  
  33.        mFrameLayout.addView(mCameraView);  
  34.        // Added by MyArrow end  
  35.   
  36.        // Cocos2dxGLSurfaceView  
  37.        this.mGLSurfaceView = this.onCreateView();  
  38.        //this.mGLSurfaceView.setBackgroundColor(Color.BLUE);  
  39.   
  40.        // ...add to FrameLayout  
  41.        mFrameLayout.addView(this.mGLSurfaceView);  
  42.   
  43.        // Switch to supported OpenGL (ARGB888) mode on emulator  
  44.        if (isAndroidEmulator())  
  45.           this.mGLSurfaceView.setEGLConfigChooser(8888160);  
  46.   
  47.        // Added by MyArrow on 2014-10-28    
  48.        this.mGLSurfaceView.setEGLConfigChooser(8 , 888160);    
  49.        this.mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);    
  50.        this.mGLSurfaceView.setZOrderOnTop(true);    
  51. // Added by MyArrow end  
  52.   
  53.        this.mGLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer());  
  54.        this.mGLSurfaceView.setCocos2dxEditText(edittext);  
  55.   
  56.        // Set framelayout as the content view  
  57.        setContentView(mFrameLayout);  
  58.    }  

2. 效果图




1
2

我的同类文章

 
 
GongshangLogo

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多