I am trying to use SurfaceView. So I created a SurfaceView widget in the layout file as shown below in the code. The problem I have is how to set a weight to the SurfaceView? As shown below in the code I set :
android:layout_weight=".4"
but still the SurfaceView occupies the eintire screen, what i want is to make the SurfaceView occupies only 40% of the screen. I also refered to a post in this link SurfaceView in Layout but it does not show how to set the weight to the SurfaceView from the xml file.
Please let me know how to set weight to the SurfaceView from the xml file.
code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.surfaceview_00.MainActivity">
<SurfaceView
android:id="@+id/mainActivity_surfaceView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".4"/>
</RelativeLayout>
update:
I also tried the below code but still i got one SurfaceView that occupies the whole screen. I expected after running the below code is to have two SurfaceViews each occupies half of the screen, but i got only one
code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.surfaceview_00.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<SurfaceView
android:id="@+id/mainActivity_SurfaceView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<SurfaceView
android:id="@+id/mainActivity_SurfaceView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</RelativeLayout>