我正在使用以下代码构建一个新的XML文档:
doc = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do
reginfo {
client_type_id client_type == :associate ? ASSOCIATE : CLIENT
parent_ {
id_ client_type == :associate ? associate_id : customer_id
client_type_id client_type == :associate ? ASSOCIATE : CLIENT
vsn client_type == :associate ? associate_vsn : customer_vsn
}
}
end
上面标记为client_type_id
的标记显示在XML文件中,如client_type_id
,但这不是正确的XML标记名称格式。我需要他们client-type-id
。
我尝试用以下代码替换该行:
:"client-type-id" client_type == :associate ? ASSOCIATE : CLIENT
但我明白了:
syntax error, unexpected tIDENTIFIER, expecting '}'
:"client-type-id" client_type == :associate ? ASSOCIATE : CLIENT
^
或:
:"client-type-id" (client_type == :associate ? ASSOCIATE : CLIENT)
但我明白了:
syntax error, unexpected '(', expecting '}'
:"client-type-id" (client_type == :associate ? ASSOCIATE : CLIENT)
^
有没有办法告诉Nokogiri :: XML :: Builder:
答案 0 :(得分:0)
有一种奇特的方式:
RelativeLayout parentLayout = (RelativeLayout) findViewById(R.id.parent_layout);
int height = parentLayout.getHeight();
int targetWidth = (int)Math.round(height / 0.5625); //example for 16:9 ratio
ImageView imageView = new ImageView(this);
imageView.setLayoutParams(new ViewGroup.LayoutParams(
targetWidth,
ViewGroup.LayoutParams.MATCH_PARENT
));
parentLayout.addView(imageView);