Reputation: 12018
I have one SurfaceView
for which I want to display a border of 20dp
size which will flow around the SurfaceView
. I need 'SurfaceView' in 16:9
aspect ratio, so i kept the size of the SurfaceView
to 161x286
which is in 16:9
ratio.
To display border around the surface view i have following implementation in XML.
<RelativeLayout
android:id="@+id/my_surface_view_holder"
android:layout_height="161dp"
android:layout_width="286dp"
android:padding="20dp"
android:focusable="true"
android:clickable="true"
android:background="#fff"
>
<SurfaceView
android:id="@+id/video_surface_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
Above code displays the border around the SurfaceView
properly but it breaks the 16:9 aspect ration of the video as i have given padding of 20dp
for displaying border.
If i adjust aspect ration according to the border size then border is not evenly set, on top/bottom it is different and on left/right it is different.
So How can i display the border around SurfaceView by keeping it's aspect ration maintained to size 161x286.
Thanks.
Upvotes: 1
Views: 3586
Reputation: 12018
I found out the way and it was pretty simple. I set the size of SurfaceView to 161X286 and then i set the RelativeLayout to wrap contains for width and height and then i set padding to the RelativeLayout which displays the border around the SurfaceView.
So my SurfaceView maintains the aspect Ration of 16:9 and it has RelativeLayout as it's background border.
Thanks everyone for your comments.
Upvotes: 4