我将这些数字标记为这样.
---
title: "xxx"
output:
pdf_document:
fig_caption: true
---
Run Code Online (Sandbox Code Playgroud)
然后在每个块中
```{r, fig.cap="some caption"}
qplot(1:5)
```
Run Code Online (Sandbox Code Playgroud)
这很好用.然而,在我在循环中绘制多个数字的块中,我无法指定标题.这根本没有产生标题:
```{r, fig.cap="another caption"}
qplot(1:5)
qplot(6:10)
```
Run Code Online (Sandbox Code Playgroud)
如何为每个绘图指定一个与第一个块相同数字的数字?
我有一个范围,如果满足条件,我想反转该范围。因为将以与简单交换数字for i in 0..9相同的方式进行迭代是行不通的。for i in 9..0也不(0..9).stepy_by(-1)是一个选项,因为.step_by()只接受usize. 因此我尝试实施如下内容:
fn create_range(rev: bool) -> Range<usize> {
if rev {
0..9
} else {
(0..9).rev()
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这也不起作用,因为0..9返回 aRange<usize>但(0..9).rev()返回 aRev<Range<usize>>所以类型不匹配。
我最终将循环中调用的所有内容都放在函数中,但我对此并不满意。
if rev {
for i in (0..9).rev() {
do_stuff(i);
}
} else {
for i in 0..9 {
do_stuff(i);
}
}
Run Code Online (Sandbox Code Playgroud)
问题是:如果满足条件,是否可以简单地反转范围?
在我Fragemt.java有这样的事情:
public class MainFragment extends Fragment implements View.OnClickListener {
private TextView mTitleTextView;
[...] irrelevant code cut out
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
[...] some other code
mTitleTextView = (TextView) rootView.findViewById(R.id.titleTextView);
mTitleTextView.setText("Text I Want to Set"); // Problem! App crashes on start if TextView isn't part of the fragment
[...] more irrelevant code
Run Code Online (Sandbox Code Playgroud)
这现在工作正常。在应用程序总是crashed加载之后,我搜索了几个小时。问题是TextView (R.id.titleTextView)位于XML父活动的 中,而不是分配给片段的 xml。
有没有办法可以TextView从片段java代码中更改父母的文本?
编辑 logcat …
在我的FXML项目中,我不想硬编码布局中的所有常量.边距和填充等简单的东西.我宁愿把它们放在一个地方.我该怎么办?
我可以使用常量创建一个类并在我的fxml布局中访问它们吗?我知道fx:define但我必须在每个fxml文件中重复这个.或者有没有办法fx:在中央文件中定义并将其附加到我的所有fxml布局?或者也许有类似于我用于内化的资源包?