Horizontal Scroll

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kosmo
Posts: 15
Joined: Mon Feb 17, 2014 6:05 pm

Horizontal Scroll

Post by kosmo » Fri Feb 28, 2014 7:12 pm

I took the lesson for a vertical scroll android field and am trying to do a horizontal scroll. Can this be done? I tried to duplicate the vertical scroll data to the horizontal scroll...but it still isn't working.

http://lessons.runrev.com/s/lessons/m/4 ... ll-a-field

I put the code I added in bold/red. I also changed the field in the lesson to a non wrap field expecting to be able to scroll through it horizontally.

Here is the code:

local sScrollerID

on preOpenCard
local tScrollerRect, tContentRect

// Only create a scroller on a mobile device
if environment() is not "mobile" then exit preOpenCard

// Set the area of the scroller
put the rect of group "scrollArea" into tScrollerRect

// Set the are of the content to be scrolled
put the left of field "lorem",the top of field "lorem",the right of field "lorem",the formattedHeight of field "lorem" into tContentRect

// Create the scroller control
mobileControlCreate "scroller", "loremScroll"
put the result into sScrollerID

// Set the properties of the scroller
mobileControlSet "loremScroll", "rect", tScrollerRect
mobileControlSet "loremScroll", "contentRect", tContentRect
mobileControlSet "loremScroll", "visible", true
mobileControlSet "loremScroll", "scrollingEnabled", true
mobileControlSet "loremScroll", "vIndicator", true
mobileControlSet "loremScroll", "hIndicator", true
mobileControlSet "loremScroll", "vscroll", 0
mobileControlSet "loremScroll", "hscroll", 0
end preOpenCard

on closeCard
// Delete the scroller
if environment() is not "mobile" then exit closeCard
mobileControlDelete sScrollerID
end closeCard

on scrollerDidScroll hOffset, vOffset
// When the user scrolls move the displayed content
set the vScroll of group "scrollArea" to vOffset
set the hScroll of group "scrollArea" to hOffset
end scrollerDidScroll

Thanks for any help!
Kosmo

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Horizontal Scroll

Post by Simon » Fri Feb 28, 2014 10:30 pm

Hi Kosmo,
Take a careful look at what this line means
put the left of field "lorem",the top of field "lorem",the right of field "lorem",the formattedHeight of field "lorem" into tContentRect
Specifically formattedHeight.
Look that up and see if you can figure out what you need to change.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

kosmo
Posts: 15
Joined: Mon Feb 17, 2014 6:05 pm

Re: Horizontal Scroll

Post by kosmo » Mon Mar 03, 2014 2:49 pm

I tried to change the scroller example to a horizontal scroll. For some reason, the text will not scroll horizontally.

I have included the stack with the changes for horizontal scroll.

Any help greatly appreciated!

Thanks,
Kosmo
Attachments
Scroller Example.zip
(3.06 KiB) Downloaded 223 times

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Horizontal Scroll

Post by Simon » Tue Mar 04, 2014 5:36 am

Hi Kosmo,
I see 2 errors in the stack.
1) Check your "on scrollerDidScroll hOffset, vOffset" command carefully... see what I see?
2) This one is not as obvious. From the lesson;
The first step is to add the content you wish to display to the stack. In this case we are using a field to display text. Make the field large enough to show all the text. Lock the size and position of the field
Now can you figure out what to do?
Watch out, liveCode doesn't remind you to save after you fix the above and so will not work in device/sim.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

kosmo
Posts: 15
Joined: Mon Feb 17, 2014 6:05 pm

Re: Horizontal Scroll

Post by kosmo » Tue Mar 04, 2014 2:36 pm

Simon,

Thanks for your help! I increased the size of the field and this did the trick. Now I can scroll horizontally!!!! :)

Kosmo

Post Reply