我是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上没有样式的设置程序,因此您必须在创建时在构造函数中进行设置。请注意,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

关于android - Ruboto水平进度栏?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23209515/

10-10 07:35