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 :
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).