简体   繁体   English

LinearLayout-在TextView之后添加TableLayout

[英]LinearLayout - adding a TableLayout after a TextView

I'm having a problem with LinearLayout where I want to display a TableLayout after a TextView. 我在LinearLayout上遇到问题,我想在TextView之后显示TableLayout。 I've tried modifying the LayoutParams however I can't seem to make it wrap (which I'm assuming I want it to do). 我试过修改LayoutParams,但是似乎无法将其包装(我假设我想这样做)。

This is simplified version: 这是简化版本:

ScrollView sv = (ScrollView) findViewById(R.id.sv);
sv.removeAllViews();

LinearLayout ll = new LinearLayout(this);
sv.addView(ll);

//This is displayed
TextView tv = new TextView(this);
tv.setText("Hello World");
ll.addView(tv);

//This is not displayed - but if I remove the above view it will display...
TableLayout tl = new TableLayout(this);
ll.addView(tl, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));

By specifiying Orientation as Vertical it worked for me: 通过将“定向”指定为“垂直”,它对我有用:

ScrollView sv = (ScrollView) findViewById(R.id.sv);
sv.removeAllViews();

LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
sv.addView(ll);

TextView tv = new TextView(this);
tv.setText("Hello World");
ll.addView(tv);

TableLayout tl = new TableLayout(this);
ll.addView(tl);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM