1

我是 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 文档吗?

4

1 回答 1

1

ProgressBar 上没有样式设置器,因此您必须在构造函数中在创建时设置它。注意 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
于 2014-04-22T09:26:59.330 回答