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.getResour开发者_Python百科ces().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.
Try using test.setLayoutParams(p);
as such:
RelativeLayout yourLayout = (RelativeLayout) getLayoutInflater().inflate(R.layout.newlayout, null, false);
setContentView(yourLayout);
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");
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
p.addRule(RelativeLayout.BELOW, R.id.detail);
test.setLayoutParams(p);
yourLayout.addView(test);
setContentView(yourLayout);
精彩评论