Android Question scrolling lable1 but lable2 get scrolling automatically by same step

aligol

Member
Hi everyone,I need it for a book.
I created two lable each take half of screen size in one is English text and the other translation text my native language, I'm afraid is there a code that when user get scroll the English text , the translation text get scrolling automatically concurrently with same step. so user only scrool lable1 one but lable2 scroll automatically. Is there a source example to learn? I'm supper new in writing codes (one week!)but eager to learn.
 

aligol

Member
Yes and I succeed to fix that But there's a problem my second lable text is not visible. here is my code. i dont know how to fix that.
here

Sub Globals
Private CLVs As List
Private Label1 As B4XView
Private Label2 As B4XView
Private CustomListView1 As CustomListView
Private CustomListView2 As CustomListView
Type LastMovedType (CLV As CustomListView, Time As Long)
Private LastMoved As LastMovedType

End Sub

Dim i As Int
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")


If File.Exists(File.DirInternal,"scrool.db") = False Then
File.Copy(File.DirAssets,"scrool.db",File.DirInternal,"scrool.db")
End If
sql.Initialize(File.DirInternal,"scrool.db",True)
Private xui As XUI


CLVs = Array(CustomListView1, CustomListView2)

For i=0 To 80
Dim v As B4XView = xui.CreatePanel("jj")
v.SetLayoutAnimated(0,0,0,100%x,40dip)
v.LoadLayout("scrool")
Label1.Text = "hhhhhhh"
CustomListView1.Add(v,"")

Next
For i=0 To 80
Dim m As B4XView = xui.CreatePanel("jj")
m.SetLayoutAnimated(0,0,0,100%x,40dip)
m.LoadLayout("scrool")
Label2.Text= "ddddd"
CustomListView2.Add(m,"")

Next
LastMoved.Initialize

End Sub



Sub CustomListView1_ScrollChanged (Offset As Int)
HandleScrollChanged(Sender, Offset)


End Sub


Sub CustomListView2_ScrollChanged (Offset As Int)

HandleScrollChanged(Sender, Offset)

End Sub



Sub HandleScrollChanged (CLV As CustomListView, offset As Int)
If LastMoved.Time + 80 < DateTime.Now Then
'new movement
LastMoved.Time = DateTime.Now
LastMoved.CLV = CLV
Else if LastMoved.CLV <> CLV Then
Return
End If
For Each c As CustomListView In CLVs
If c <> LastMoved.CLV Then
c.sv.ScrollViewOffsetY = offset
End If
Next
End Sub
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I don't think that the ScrollingLabel suggested by Erel is what you are looking for - it is a single line view intended for a limited amount of text and I don't think that it can be synchronised with a second label, but I have not checked that. You, I think, want to display a complete book and have control of the scroll position.

You can make a label scroll by putting it inside a scrollview. If you have two scrollviews, each containing a label, then it is possible to make the second scrollview and label scroll in step with the first scrollview.

But before you do that you must solve another problem. Unless every line of the English text translates into exactly one line of the other language then the two scrolling labels will soon get out-of-step. If you are planning to put a whole book inside the label then this is certainly going to happen.
 
Upvote 0

aligol

Member
I don't think that the ScrollingLabel suggested by Erel is what you are looking for - it is a single line view intended for a limited amount of text and I don't think that it can be synchronised with a second label, but I have not checked that. You, I think, want to display a complete book and have control of the scroll position.

You can make a label scroll by putting it inside a scrollview. If you have two scrollviews, each containing a label, then it is possible to make the second scrollview and label scroll in step with the first scrollview.

But before you do that you must solve another problem. Unless every line of the English text translates into exactly one line of the other language then the two scrolling labels will soon get out-of-step. If you are planning to put a whole book inside the label then this is certainly going to happen.
You know I have a set of vocabulary and difinition at my db and each suppose to be shown in ten item of a custemVeiw1 and their equivalents in native language in customListveiw2 at the same page I adjust the scroll and step but at my secony CustemList view my second lable that suppose to show my native language is invisible!


Sub Globals
Private CLVs As List
Private Label1 As B4XView
Private Label2 As B4XView
Private CustomListView1 As CustomListView
Private CustomListView2 As CustomListView
Type LastMovedType (CLV As CustomListView, Time As Long)
Private LastMoved As LastMovedType

End Sub

Dim i As Int
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")


If File.Exists(File.DirInternal,"scrool.db") = False Then
File.Copy(File.DirAssets,"scrool.db",File.DirInternal,"scrool.db")
End If
sql.Initialize(File.DirInternal,"scrool.db",True)
Private xui As XUI


CLVs = Array(CustomListView1, CustomListView2)

For i=0 To 80
Dim v As B4XView = xui.CreatePanel("jj")
v.SetLayoutAnimated(0,0,0,100%x,40dip)
v.LoadLayout("scrool")
Label1.Text = "hhhhhhh"
CustomListView1.Add(v,"")

Next
For i=0 To 80
Dim m As B4XView = xui.CreatePanel("jj")
m.SetLayoutAnimated(0,0,0,100%x,40dip)
m.LoadLayout("scrool")
Label2.Text= "ddddd"
CustomListView2.Add(m,"")

Next
LastMoved.Initialize

End Sub



Sub CustomListView1_ScrollChanged (Offset As Int)
HandleScrollChanged(Sender, Offset)


End Sub


Sub CustomListView2_ScrollChanged (Offset As Int)

HandleScrollChanged(Sender, Offset)

End Sub



Sub HandleScrollChanged (CLV As CustomListView, offset As Int)
If LastMoved.Time + 80 < DateTime.Now Then
'new movement
LastMoved.Time = DateTime.Now
LastMoved.CLV = CLV
Else if LastMoved.CLV <> CLV Then
Return
End If
For Each c As CustomListView In CLVs
If c <> LastMoved.CLV Then
c.sv.ScrollViewOffsetY = offset
End If
Next
End Sub
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Here is an example of what I mean. The code is very simple.
B4X:
Sub upper_ScrollChanged(Position As Int)
    lower.ScrollToNow(Position)
End Sub
 

Attachments

  • LinkedScroller.zip
    10.2 KB · Views: 175
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
@aligol
When you need to post code please use the CODE Tags.
To do this click on the </> icon that you can find here in the tools where you write your post.
It will open a window, just copy your code inside that window.
It will look like this
B4X:
Sub Globals
Private CLVs As List
Private Label1 As B4XView
Private Label2 As B4XView
Private CustomListView1 As CustomListView
Private CustomListView2 As CustomListView
Type LastMovedType (CLV As CustomListView, Time As Long)
Private LastMoved As LastMovedType

End Sub
It will help everyone. :)
Thanks
 
Upvote 0

aligol

Member
@aligol
When you need to post code please use the CODE Tags.
To do this click on the </> icon that you can find here in the tools where you write your post.
It will open a window, just copy your code inside that window.
It will look like this
B4X:
Sub Globals
Private CLVs As List
Private Label1 As B4XView
Private Label2 As B4XView
Private CustomListView1 As CustomListView
Private CustomListView2 As CustomListView
Type LastMovedType (CLV As CustomListView, Time As Long)
Private LastMoved As LastMovedType

End Sub
It will help everyone. :)
Thanks
LOl thanks I tried to do but didn't know how . thanks for guidance [flowers]
 
Upvote 0
Top