将代码中创建的 TextView 放置在 XML 中的 TextView 下
我到处搜索,但无法让它发挥作用。
TextView topic = (TextView) findViewById(R.id.topic);
topic.setText(json_data.getString("topic"));
TextView poster = (TextView) findViewById(R.id.poster);
poster.setText(json_data.getString("name"));
TextView detail = (TextView) findViewById(R.id.detail);
detail.setText(json_data.getString("detail"));
TextView test = new TextView(this);
test.setText("test string");
test.setTextColor(this.getResources().getColor(R.color.red));
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
p.addRule(RelativeLayout.BELOW, R.id.detail);
addContentView(test, p);
一切正常,除了最后一个文本视图(测试)仅显示在左上角。我想要它在文本视图(详细信息)下。 XML 是基于
苏伊多代码。
任何帮助将不胜感激,因为这是我的应用程序的最后一点。
I have searched high and low but can't get this to work.
TextView topic = (TextView) findViewById(R.id.topic);
topic.setText(json_data.getString("topic"));
TextView poster = (TextView) findViewById(R.id.poster);
poster.setText(json_data.getString("name"));
TextView detail = (TextView) findViewById(R.id.detail);
detail.setText(json_data.getString("detail"));
TextView test = new TextView(this);
test.setText("test string");
test.setTextColor(this.getResources().getColor(R.color.red));
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
p.addRule(RelativeLayout.BELOW, R.id.detail);
addContentView(test, p);
Everything works, other than the last textview (test) which will only show in top left. I want it under the textview (detail).
XML is based on
suedo code.
Any help would be truly appreciated as this is the last bit of my app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
test.setLayoutParams(p);
如下:Try using
test.setLayoutParams(p);
as such: