我是Android开发的新手(因此是Ruboto的新手),我有以下代码试图显示文本字段、按钮和进度条。我想把这个进度条变成一个水平进度条:
require 'ruboto/widget'
require 'ruboto/util/toast'
ruboto_import_widgets :Button, :LinearLayout, :TextView, :ProgressBar
class SplashActivity
def onCreate(bundle)
super
set_title 'some title here'
self.content_view =
linear_layout :orientation => :vertical do
@text_view = text_view :text => 'sample text.', :id => 42,
:layout => {:width => :match_parent},
:gravity => :center, :text_size => 18.0
button :text => 'foo',
:layout => {:width => :match_parent},
:id => 43, :on_click_listener => proc { bar }
progress_bar
end
rescue Exception
puts "Exception creating activity: #{$!}"
puts $!.backtrace.join("n")
end
private
def bar
@text_view.text = 'things change.'
toast 'cha-ching!'
end
end
所有元素均按预期显示。默认情况下,progress_bar
是不确定模式,将progress_bar
转换为水平模式需要哪些属性?
我发现Ruboto非常容易上手,只是找不到足够的API文档来定制控件。我在开发的应用程序中寻找的很多功能都可以在GitHub源代码中找到,但很多都被注释掉了。对于API的详细文档,我是否忽略了某些内容?
ProgressBar上没有样式的setter,所以您必须在构造函数中的创建时设置它。请注意,SplashActivity可能与Ruboto SplashActivity.java冲突,所以我使用另一个名称(ProgressBarActivity)
require 'ruboto/widget'
require 'ruboto/util/toast'
ruboto_import_widgets :Button, :LinearLayout, :TextView, :ProgressBar
class ProgressBarActivity
AndroidAttr = JavaUtilities.get_proxy_class('android.R$attr')
def onCreate(bundle)
super
set_title 'some title here'
self.content_view =
linear_layout :orientation => :vertical do
@text_view = text_view :text => 'sample text.', :id => 42,
:layout => {:width => :match_parent},
:gravity => :center, :text_size => 18.0
button :text => 'foo',
:layout => {:width => :match_parent},
:id => 43, :on_click_listener => proc { bar }
@pb = ProgressBar.new(self, nil, AndroidAttr::progressBarStyleHorizontal)
@view_parent.add_view @pb
end
rescue Exception
puts "Exception creating activity: #{$!}"
puts $!.backtrace.join("n")
end
def onResume
super
@pb.progress = @pb.max / 2
end
private
def bar
@text_view.text = 'things change.'
@pb.progress = 2 * @pb.max / 3
toast 'cha-ching!'
end
end