gpt4 book ai didi

android - Ruboto水平进度条?

转载 作者:行者123 更新时间:2023-11-30 02:56:16 25 4
gpt4 key购买 nike

我是 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默认是indeterminate模式,需要什么属性才能把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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com