Do you mean full-screen viewing?
I am using this code:
this.requestWindowFeature(Window.FEATURE_NO_TITLE); //no title getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //no status bar, etc
and this:
setContentView(R.layout.main); addContentView(overlay, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); ((FrameLayout) findViewById(R.id.preview)).addView(preview);
the first fragment sets the application to full screen mode and hides the title and status bar. the second snippet adds my overlay (extended view) to the main layout.
Here is my xml and java code: main.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <FrameLayout android:id="@+id/preview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> </LinearLayout>
Overlay.java:
class Overlay extends View { String text = ""; String textBearing = "Bearing: "; public Overlay(Context context) { super(context); } @Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); paint.setTextSize(16); canvas.drawText(text, 20, 20, paint); canvas.drawText(textBearing, 20, 50, paint); super.onDraw(canvas); } }
And my activity:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); //no title getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //fullscreen overlay = new Overlay(this); setContentView(R.layout.main); addContentView(overlay, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); camera = getCameraInstance(); //camera.open(); preview = new Preview(this, camera); ((FrameLayout) findViewById(R.id.preview)).addView(preview); }
Hope this helps
v1r0x source share