Android Question Move to the Right Position In code

Luis Felipe Andrade

Member
Licensed User
Hello, good afternoon, someone knows how to move the image of the clock to the right next to where the date ends? The first thing I tried was to use the width = -2 that does a resize of the label and it actually does, but then to position the clock next to the date I Wrote: Imageview5.left = labeldate.left + labeldate.width, but unfortunately the widht stayed in -2 and therefore it is not possible, in Erel's example when someone ask that, he says to use the autotextsizelabel but that is used for the size of the text adapts to the size of the label, therefore it does not work. Obviously the Right property does not exist for images, in the designer code I already wrote ImageView5.Left = LabeldateEsp.Right because there obviously exist the Right property, but the value acquires it since the design is charged therefore it does not work either, if someone knows I appreciate it. regards
 

Attachments

  • reloj.jpeg
    reloj.jpeg
    175 KB · Views: 162

josejad

Expert
Licensed User
Longtime User
Hi, have you tried this class?

 
Upvote 0

Luis Felipe Andrade

Member
Licensed User
Hi, have you tried this class?

Hello Jose, thank you for your response but is not theme about clock, what I need is to possition an element just to the right to anoher element, even if the element that is on the left change it's lengh, in the example I try to maintain together the label and the imageview, looks very easy if in the designer code I write imageview1.left=label1.right but in the run time the label change it's lenght an the image view must be juts to the right side no mather the lenght of the label, using the trick label1.width=-2 the label resisez very good, but, how to move the imagen to the new position at the right?
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Sorry, I misunderstood it.
Maybe you can use this example, to get the right position

 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Hi Aeric:

I think OP means he can do it in design script, but if the date changes in runtime, he needs the clock to move again just beside the date:
i.e.:
Wednesday, 31 of December 2021 (CLOCK)
Sunday, 1 of June 2021 (CLOCK)<--moves to the left
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
You can get the width with JavaObject:

B4X:
    Private jo = Label1 As JavaObject
    Width = jo.RunMethod("getWidth", Null)

Maybe you need to add a Sleep(0) after setting the new positions.

I tested it with this code:
B4X:
Private Sub Button_Click
    Private Width As Int
    
    Private jo = Label1 As JavaObject
    Label1.Text = "Test text text"
    Label1.Width = -2
    Sleep(0)
    Width = jo.RunMethod("getWidth", Null)
    Button1.Left = Label1.Left + Width + 10dip
End Sub
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
labeltest.png

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Label1 As B4XView
    Private Timer1 As Timer
    Dim CurrentDate As String
    Dim CurrentTime As String
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Timer1.Initialize("Timer1", 1000)
    Timer1.Enabled = True
    DateTime.DateFormat = "EEEE, MMMM dd yyyy"
    DateTime.TimeFormat = "HH:mm:ss"
    CurrentDate = DateTime.Date(DateTime.Now)
    CurrentTime = DateTime.Time(DateTime.Now)
End Sub

Private Sub Timer1_Tick
    CurrentTime = DateTime.Time(DateTime.Now)
    Dim cs As CSBuilder
    cs.Initialize.Size(14).Typeface(Typeface.MONOSPACE)
    cs.Color(Colors.Black)
    cs.Image(LoadBitmap(File.DirAssets, "icon-calendar.jpg"), 14dip, 14dip, True).Append(" ").Append(CurrentDate).Append(" ")
    cs.Image(LoadBitmap(File.DirAssets, "icon-clock.png"), 14dip, 14dip, True).Append(" ").Append(CurrentTime).Append(" ")
    cs.Image(LoadBitmap(File.DirAssets, "icon-weather.png"), 14dip, 14dip, True).Append(" ").Append("30°C")
    cs.PopAll
    Label1.Text = cs
End Sub

Private Sub Button1_Click
    Dim Yesterday As Long = DateTime.Add(DateTime.Now, 0, 0, -1)
    CurrentDate = DateTime.Date(Yesterday)
End Sub

Private Sub Button2_Click
    CurrentDate = DateTime.Date(DateTime.Now)
End Sub

Private Sub Button3_Click
    Dim Tomorrow As Long = DateTime.Add(DateTime.Now, 0, 0, 1)
    CurrentDate = DateTime.Date(Tomorrow)
End Sub
 
Upvote 0
Top