infinitered / bluepotion

Like RedPotion, but for Android
MIT License
74 stars 18 forks source link

Implementing a ScrollView #120

Closed uksa closed 8 years ago

uksa commented 8 years ago

I've attempted to implement a scroll view, with minor success, any chance you could help me with completing it!

I've created a scroll_view_styler with view set too true

  def fill_view_port=(bool)
    @view.fillViewport = bool
  end 

My stylesheet main_scroll is:

  def main_scroll(st)
     st.fill_view_port = true
     st.layout_width = :match_parent
     st.layout_height = :wrap_content
  end

And in the on_load I've added in the objects

  rmq.append(Potion::ScrollView, :main_scroll)
  rmq.append(Potion::ScrollView).append(Potion::TextView, :some_text)

I've set the :some_text top in the frame to a very large value. So that it appears off the window, to scroll to.

However the result is the scroll bar can be seen, although it won't actually scroll. Any ideas?

uksa commented 8 years ago

So after a bit of experimenting using a Layout instead. I figured out that a Scrollview requires a Relative or Linear view, which will then contain a collection of your objects (TextView/Image etc)

rmq.append(Potion::ScrollView, :main_scroll).append(Potion::RelativeLayout)

You then have to find the ReletiveLayout and append your objects, otherwise you may get an error about only one child view...

rmq.find(Potion::RelativeLayout).append(Potion::TextView, :scroll_style)

Following style will then scroll.

def scroll_style(st)
    st.color = rmq.color('#ffffff')
    st.text = "scroll!\r\n" * 50
    st.background_color = rmq.color('#200163')
    st.text_size = 14
  end

I'll put this into a pull request so you can see the complete code.