Android Question Resize webviews flickers very much

Alessandra Pellegri

Active Member
Licensed User
Longtime User
My intent is show two webviews horizontally separated buy a thin button.
Sliding this button I should resize webviews like a splitter in Windows 7.

I created this code:
B4X:
#Region  Project Attributes
   #ApplicationLabel: B4A Example
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: True
#End Region

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim wStartX, wStartY As Int
End Sub

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

   Private Button1 As Button
   Private WebView1 As WebView
   Private WebView2 As WebView
   Dim TouchSlop As Int
  
   Private Panel1 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("Prima")
   Dim r As Reflector
   r.Target = r.RunStaticMethod("android.view.ViewConfiguration", "get", Array As Object(r.GetContext), Array As String("android.content.Context"))
   TouchSlop = r.RunMethod("getScaledTouchSlop")  
   Button1.Height=30dip
   Button1.Width=Panel1.Width
   Button1.Left=0
   Button1.Top=Panel1.Height-Button1.Height
   WebView2.Width=Panel1.Width
   WebView2.Top=Panel1.Height
   SetOnTouchListener(Button1)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub SetOnTouchListener(MyView As View)
   Dim r As Reflector
   r.Target = MyView
   r.SetOnTouchListener("Content_Touch")
End Sub

Private Sub Content_Touch(ViewTag As Object, Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
   Select Action    
     Case 0
       wStartY=Y
     Case 2
       Dim MoveQty As Int = Abs(Y-wStartY)
       If (MoveQty>TouchSlop) Then
         Panel1.Height=Panel1.Height+Y-wStartY
         Button1.Top=Panel1.Height-Button1.Height
         WebView2.Top=Panel1.Height
         wStartY=Y
       End If
   End Select
   Return True
End Sub
WebView1 and Button1 are part of Panel1, instead WebView2 is under Activity.

The code seems to work, but flickers very much and the button1 doesn't remain exactly locked to the finger.

Someone could help me ?

Thank you
 
Top