Android Question XMLLayoutBuilder change programatically width and height layout

ronovar

Active Member
Licensed User
Longtime User
i have this XML Code:

I declared in B4A this:

FFMpegVideoView1 = Xml.GetView("videoViewRelative")

B4X:
<RelativeLayout
 
android:layout_width="658dp" 
android:layout_height="438dp"
 android:layout_alignParentTop="true"
 android:layout_alignParentRight="true"
 android:paddingTop="100dp"
 android:paddingRight="71dp" >
 
 <ImageView
 android:id="@+id/imgPreview"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:src="@drawable/preview" />
 
 <tv.danmaku.ijk.media.widget.VideoView
 android:id="@+id/videoViewRelative"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 </tv.danmaku.ijk.media.widget.VideoView>
 </RelativeLayout>

i Need in B4A only change layout_width and layout_height so how to do that?

I need to change:

B4X:
android:layout_width="658dp" 
android:layout_height="438dp"

To

B4X:
android:layout_width="fill_parent"
android:layout_height="fill_parent">

And Remove:

B4X:
android:paddingTop="100dp"
 android:paddingRight="71dp"

And add:

B4X:
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"

So that the modified xml looks:

B4X:
<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <tv.danmaku.ijk.media.widget.VideoView
            android:id="@+id/videoViewRelative"
            android:layout_alignParentTop="true"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
        </tv.danmaku.ijk.media.widget.VideoView>
     </RelativeLayout>

This code works for FULLSCREEN and SMALLSCREEN for video preview of video...so when i press OK button on remote control to get desired state...how can i programatically change layout of videoViewRelative?
 

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
It would not be better you have two versions of xml file and loads them each in desired place?

Sorry if I have not understood well the question.
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
I need to switch from Small Screen To Full Screen so setting FFmpeg from to:

android:layout_width="658dp"
android:layout_height="438dp"

To

android:layout_width="fill_parent"
android:layout_height="fill_parent"

Will make FFmpeg to show full screen.

If i make removeview and then xml load ffmpeg will stop playing and have delay around 2-3seconds to strat playing video with new layout :)

So only way is to programatically change layout width and height.

I have try this to get layout params:

B4X:
Dim r As Reflector
r.Target = FFMpegVideoView1

Log(r.RunMethod("getLayoutParams"))

I get from Log:

B4X:
android.widget.RelativeLayout$LayoutParams@41a8a060

So as you can see i get RelativeLayout Parameters from XML file that i have defined...so now i need to call:

B4X:
privatevoid setDimensions(View view,int width,int height){
android.view.ViewGroup.LayoutParamsparams= view.getLayoutParams();params.width = width;params.height = height;
view.setLayoutParams(params);}

Now i don't know how to add width and height to getLayoutParams and then to call setLayoutParams(params)

I try usig reflector and i get handler for getLayoutParams.

How to call setLayoutParams using reflector or java object?
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Here is the solution...it is very easy:

B4X:
'PLAY - Channel
    If (FFMpegVideoView1.IsPlaying = False) Then
        FFMpegVideoView1.SetVideoPath(Value)
    End If

    If (FullScreen = False) Then
                'SET - FullScreen
                Dim view As JavaObject = Xml.GetView("videoView")

                Dim jo As JavaObject
                jo.InitializeContext
                jo.RunMethod("setFullScreen", Array(view, 100%x, 100%y))

                FullScreen = True
                Log("Full...")
            Else
                'SET - SmallScreen
                Dim view As JavaObject = Xml.GetView("videoView")

                Dim jo As JavaObject
                jo.InitializeContext
                jo.RunMethod("setSmallScreen", Array(view, 658, 438))

                FullScreen = False
                Log("Small...")
            End If

#If Java
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.util.Log;

public void setFullScreen(View view, int width, int height){
    android.view.ViewGroup.LayoutParams params = view.getLayoutParams();
    params.width = width;
    params.height = height;
    view.setLayoutParams(params);
    view.setPadding(0, 0, 0, 0);
}

public void setSmallScreen(View view, int width, int height){
    android.view.ViewGroup.LayoutParams params = view.getLayoutParams();
    params.width = width;
    params.height = height;
    view.setLayoutParams(params);
    view.setPadding(0, 102, 73, 0);
}
   
#End if
 
Upvote 0
Top