1

I have the following setup :

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainView" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:layout_margin="0dp"
    android:gravity="bottom" android:orientation="vertical"
    android:background="@color/yellow_background" android:padding="0dp">

    <!-- There are some components here, but they aren't required to reproduce the bug -->

    <SurfaceView
        android:id="@+id/player" android:focusable="false"
        android:layout_width="match_parent"
        android:layout_height="800dp" />

</LinearLayout> 

And my code (some bits, if you need more information, just ask) :

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  // fullscreen
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

  setContentView(R.layout.main);
  surfaceView = (SurfaceView) this.findViewById(R.id.player);
  surfaceView.setDrawingCacheEnabled(false);
  surfaceHolder = surfaceView.getHolder();
  surfaceHolder.setKeepScreenOn(true);
  surfaceHolder.addCallback(this);
}


public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
  canvasWidth = width;
  canvasHeight = height;
}

// lots of code 

The result : Image with a border

The question is : why surfaceChanged is called with an height of 798 instead of 800 (same value as the SurfaceView)? I'm getting a 2dp border inside the second SurfaceView, and this is pretty bad. Tried to set padding without success. The solution provided by how to make surfaceview transparent worked, but it is a bit hackish and slows down my app.

(Note: I don't think Size of a Canvas in a Surfaceview against real screen resolution does apply to my case, I'm testing it anyway)

Note 2 : The screenshot doesn't reflect exactly the XML above, it was a test with a 500dp height, and the same 2dp border appeared.

The environment:
- Android Emulator (I don't have access to the tablet to test);
- SDK Tools r18/r19;
- Under MacOS 10.7;
- The device is in PORTRAIT mode (WXGA resolution, Android 3.2).

Community
  • 1
  • 1
Marcelo Alves
  • 1,856
  • 11
  • 12
  • Have you pasted the full content of `main.xml` file? – a.ch. Apr 13 '12 at 17:13
  • Besides, [Hierarchy Viewer](http://developer.android.com/guide/developing/debugging/debugging-ui.html#HierarchyViewer) might help you. – a.ch. Apr 13 '12 at 17:15
  • Just the minimum to show the problem. There's more content before the SurfaceView, but the problem appears with or without them. Why? – Marcelo Alves Apr 13 '12 at 17:16
  • @a.ch. Oh, let me take a look into this tool. Thanks! (I'm not an Android expert). If it does solve / help me, I'll let you know. – Marcelo Alves Apr 13 '12 at 17:17

0 Answers0