例如,如果我有这样的空布局:
layout1.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
以及其他一些布局:
layout2.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
android:layout_weight="1"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我想layout2.xml以layout1.xml编程方式添加.我需要有多个不同的版本layout2.xml,我会在需要时添加.每个文本在TextView和Buttons上都有不同的文本.
在常规Android View的情况下,我通常会像这样做addView:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv1 = new TextView(this);
tv1.setText("HELLO");
my_linear_layout.addView(tv1);
Button btn2 = new Button(this);
bt2.setText("WORLD");
my_linear_layout.addView(btn2);
}
Run Code Online (Sandbox Code Playgroud)
如果我没有像TextView或Button这样简单的东西,并且我有自己的xml定义View,我怎么能这样做呢?
是否有可能以某种方式将所有视图放在适配器中,就像ListView一样,然后在需要时获取它并只调用addView那些视图?
我试图得到RecyclerView孩子的数量.我试过这个:
myRView.getChildCount();
Run Code Online (Sandbox Code Playgroud)
还有这个:
LinearLayoutManager lm = ((LinearLayoutManager)myRViews.getLayoutManager());
lm.getChildCount();
Run Code Online (Sandbox Code Playgroud)
我需要让孩子在某个位置查看,这就是我需要它的原因.如果我打电话,getChildAt(index)我从来没有得到任何孩子查看
这两种方法都返回0.如何从RecyclerView获取子视图?我的项目显示正确,一切正常.我在创建适配器并将其设置为RecyclerView后调用这些方法.谢谢您的帮助.
我想在我的网站上声明不同的用户角色,我想知道在 Rails 中执行此操作的最佳实践是什么?现在我有两个选择:
选项1:
我创建表 Users 并声明一个字符串列,我可以在其中存储用户角色的名称(超级管理员、管理员、教练、玩家)
create_table "users", force: true do |t|
t.string "username"
t.string "first_name"
t.string "last_name"
t.string "email"
t.string "role"
end
Run Code Online (Sandbox Code Playgroud)
在 User 类中,我保存这样的值:
class User < ActiveRecord::Base
ROLES = %w[SuperAdmin, Admin, Player, Coach]
end
Run Code Online (Sandbox Code Playgroud)
选项 2:
我仅为角色创建一个单独的表。在 Users 表中,我有用于存储 role_id 的整数列:
create_table "users", force: true do |t|
t.string "username"
t.string "first_name"
t.string "last_name"
t.string "email"
t.integer "role_id"
end
create_table "roles", force: true do |t|
t.string "role_name"
end
class User < ActiveRecord::Base
belongs_to :role
end
class Role …Run Code Online (Sandbox Code Playgroud) 我试图在我的Rails网站上设置AddThis插件,但目前只取得了部分成功.问题是它不能像turbo-links一样工作.AddThis共享按钮仅在页面刷新后出现.如果我点击网站的其他部分,AddThis工具栏将消失.如果我禁用turbo-links,那么它将适用于网站的每个部分.
这是我生成智能图层时的代码:
<!-- AddThis Smart Layers BEGIN -->
<!-- Go to http://www.addthis.com/get/smart-layers to customize -->
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=xxx"></script>
<script type="text/javascript">
addthis.layers({
'theme' : 'transparent',
'share' : {
'position' : 'left',
'numPreferredServices' : 5
}
});
</script>
<!-- AddThis Smart Layers END -->
Run Code Online (Sandbox Code Playgroud)
该代码当然不适用于turbo-links.我发现这个解决方案' 如何使用turbilinks rails 4添加这项工作,作者证实它有效,但当我点击网站的其他部分时我仍然有问题.
我试图head在我的application.html.erb文件中的标记内插入此代码:
<!-- AddThis Smart Layers BEGIN -->
<!-- Go to http://www.addthis.com/get/smart-layers to customize -->
<script type="text/javascript">$(document).ready(function() {
var script="//s7.addthis.com/js/300/addthis_widget.js#pubid=xxx";
if (window.addthis){
window.addthis = null;
window._adr = null; …Run Code Online (Sandbox Code Playgroud) 我知道我可以得到这样的用户IP地址:
remote_ip = request.remote_ip
Run Code Online (Sandbox Code Playgroud)
现在我想知道如何从他的IP地址找出用户的国家和城市?我发现这只买国家:
http://api.hostip.info/country.php
Run Code Online (Sandbox Code Playgroud)
城市可以这样找到:
http://api.hostip.info
Run Code Online (Sandbox Code Playgroud)
问题是它没有正确显示城市.我目前在世界上最大的城市之一,它说这是一个未知的城市.
从他的IP地址中找出用户所在国家和城市的最佳方法是什么?我正在寻找一个免费的解决方案或至少非常便宜的东西.
谢谢 :)
我想用RMagick在我的图像上添加文字.这是我的代码:
version :thumb do
process :resize_to_limit => [400, 300]
process :addt
end
def addt
manipulate! do |img|
title = Magick::Draw.new
img = title.annotate(img, 0,0,0,40, 'test') {
self.font_family = 'Helvetica'
self.fill = 'white'
self.stroke = 'transparent'
self.pointsize = 32
self.font_weight = Magick::BoldWeight
self.gravity = Magick::CenterGravity
}
end
end
Run Code Online (Sandbox Code Playgroud)
这段代码的问题在于它完全阻止了我的应用程序.我无法打开我的网站的任何其他部分,无法关闭我的服务器进程.我需要完全杀死服务器进程才能再次启动应用程序.
可能有什么问题?
正如你所看到的,我有一个非常敏感的问题:)我正在构建一个网站,用户可以选择订阅某些内容.我正在使用Rails 4.用户将使用信用卡支付订阅费用.同时,管理员可以根据需要进行退款.管理员可以对任何付费订阅的百分比进行退款.
据我了解,不建议在我的数据库中存储任何信用卡数据.我发现了一些与此问题相关的文章:
http://railscasts.com/episodes/288-billing-with-stripe?view=asciicast
http://larsgebhardt.de/credit-card-processing-with-ruby-on-rails/
http://www.subelsky.com/2011/10/how-to-setup-credit-card-payments-for.html
我想知道目前推荐的信用卡处理方法是什么?我应该如何处理Rails 4应用程序中的信用卡处理?这可能很简单,但如果我的数据库中没有任何信用卡信息,如何退款?
谢谢!
android ×2
ruby ×2
activerecord ×1
addthis ×1
credit-card ×1
geocoding ×1
ip-address ×1
javascript ×1
rmagick ×1
security ×1
turbolinks ×1
watermark ×1
xml ×1