我对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文档,我有什么东西可以忽略吗?
答案 0 :(得分:1)
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