Android Question Label on top of imageview is not showed

TrisectDevelopment

Active Member
Licensed User
Longtime User
I have some code where I record a video and have a imageview on top of my view.
Its recording okay and the image is visible.

Then I put a label on top of my imageview and set a timer to count seconds.
I set the label to BringToFront but when I run my App its behind the imageview.

If I place the label just above the imageview is shown.

Layout is created in designer.

Heres my code:
B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region

'**********************************************
'** Process Globals
'**********************************************
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim CounterTimer As Timer

End Sub

'**********************************************
'** Globals
'**********************************************
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private pnlVideo As Panel
    Private btnRecording As ImageView
    Private lblCounter As Label
   
    Dim phone As Phone
    Dim record As RSVideoRecord                            '** Bruges til at optage video
    Dim theCounter As Int   
End Sub

'**********************************************
'** Activity create
'**********************************************
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Try
        '** Load layout
        Activity.LoadLayout("videoLayout")

        If FirstTime = False Then
            '** Initialize video
            record.Initialize(pnlVideo, "record")
           
            '** Initialize timer
            CounterTimer.Initialize("CounterTimer", 1000)
           
            '** Nulstil counter
            theCounter = 0
        End If

        '** Vis knappen       
        btnRecording.Enabled = True
        btnRecording.Visible = True
       
        '** Vis counter
        lblCounter.Enabled = True
        lblCounter.Visible = True
        lblCounter.BringToFront
    Catch
        Log("Video - Activity_Create - " + LastException.Message)
    End Try
End Sub

'**********************************************
'** Activity resume
'**********************************************
Sub Activity_Resume
    Try
        '** Sæt den til landscape
        phone.SetScreenOrientation(0)

        '** Initialize video
        'record.Initialize(pnlVideo, "record")
       
        '** Sæt record knappen frem
        btnRecording.BringToFront
    Catch
        Log("Video - Activity_Resume - " + LastException.Message)
    End Try
End Sub

'**********************************************
'** Activity pause
'**********************************************
Sub Activity_Pause (UserClosed As Boolean)
    Try
        record.Release
    Catch
        Log("Video - Activity_Pause - " + LastException.Message)
    End Try
End Sub

'**********************************************
'** Recording button
'**********************************************
Sub btnRecording_Click
    Try
        '** Vis knappen       
        btnRecording.Enabled = False
        btnRecording.Visible = False

        '** Skjul knappen       
        btnRecording.Enabled = False
        btnRecording.Visible = False

        '** Stop timer
        CounterTimer.Enabled = False
       
        '** Release og stop recording
        record.stop
        record.resetMediaRecorder
        record.releaseMediaRecorder
        record.lockCamera       

        '** Sæt den til unspecified
        phone.SetScreenOrientation(-1)

        '** Sæt at video er optaget
        Functions.iVideo = 1
       
        '** Spring til menu
        StartActivity(Main)
        Activity.Finish       
    Catch
        Log("Video - btnRecording_Click - " + LastException.Message)
    End Try
End Sub

'**********************************************
'** Timer events
'**********************************************
Sub CounterTimer_Tick
    Try
        '** Skriv counter i label
        lblCounter.Text = theCounter
       
        '** Increment counter
        theCounter = theCounter + 1
    Catch
        Log("Video - CounterTimer_Tick - " + LastException.Message)
    End Try   
End Sub

'**********************************************
'** Recording events
'**********************************************
Sub record_Ready (Success As Boolean)
    Try
        If Success Then
            '** Start preview
            record.StartPreview
           
            '** Skriv at video er startet
            ToastMessageShow("Video optagelse er startet.",False)

            '** Enable timer           
            CounterTimer.Enabled = True

            '** Sæt parameter
            SetVideoParameter
        Else
            ToastMessageShow("Kan ikke åbne kamera.", True)
        End If
    Catch
        Log("Video - record_Ready - " + LastException.Message)
    End Try
End Sub

Sub SetVideoParameter
    Try
        'For the constants
        record.unlockCamera
        record.initMediaRecorder()
        record.AudioSource = 5
        record.VideoSource = 1
        record.OutputFormat = 2
        record.setScreenSize(640,480)
        record.AudioEncoder = 1
        record.VideoEncoder = 3
        'record.Profile = 1
        record.setOutputFile(File.DirDefaultExternal,"movie.mov")
        record.setPreviewDisplay
       
        record.prepare
       
        record.start
    Catch
        Log("Video - record_Ready - " + LastException.Message)
    End Try
End Sub
 

ilan

Expert
Licensed User
Longtime User
The imageview bringtofront is after the label bringtofront so imageview will be above label.

Avtivity create will be called and THEN activity resume... (on every app start!)

Btw. Why are you puting every code in try catch?? Especially activity create...
 
Upvote 0

TrisectDevelopment

Active Member
Licensed User
Longtime User
Hi

Thanks, I did not see that. :(
But its working now.:)

Regarding try-catch, I'm also a Object-C and C# programmer and Allways use try-catch to catch error.
I guess its just habit of mine.

Is there a reason not to use try-catch?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Yes,

Its important to get a crash report to know whats wrong with your code and fix it. If your code is running on 1 device this doesnot mean it will run on another device so better keep the sub clean from try catch.

Only in some special places it should be used but in your code i dont see a reason to use try catch.

https://www.b4x.com/android/forum/threads/when-to-use-try-catch-block.56844/
 
Upvote 0

TrisectDevelopment

Active Member
Licensed User
Longtime User
Okay I removed all my try-catch and will only use it when finding error under development.

You know old habits are not easy to break.

Thanks again for your help.
 
Upvote 0
Top