android - How to force SurfaceView to occupy specific section othe screen -


i trying use surfaceview. created surfaceview widget in layout file shown below in code. problem have how set weight surfaceview? shown below in code set :

android:layout_weight=".4" 

but still surfaceview occupies eintire screen, want make surfaceview occupies 40% of screen. refered post in link surfaceview in layout not show how set weight surfaceview xml file.

please let me know how set weight surfaceview 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 tried below code still got 1 surfaceview occupies whole screen. expected after running below code have 2 surfaceviews each occupies half of screen, got 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> 

relativelayout not support layout_weight. need use linearlayoutfor that.

read more @ https://developer.android.com/guide/topics/ui/layout/linear.html

but change something this:

<?xml version="1.0" encoding="utf-8"?> <linearlayout 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:orientation="vertical"       android:layout_height="match_parent"       android:weightsum="1">           <surfaceview               android:id="@+id/mainactivity_surfaceview"               android:layout_width="wrap_content"               android:layout_height="wrap_content"               android:layout_weight=".4"/>  </linearlayout> 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -