2013-04-04 65 views
0

根据我的要求,我应该只给出水平方向,如果我在3个文本视图中给出3个句子,如果没有第三个句子的空间,那么它应该进入下一行第一位置...Android - JAVA文件中的布局

公共类MainActivity扩展活动{

private LinearLayout layout; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_main); 

    findViewById(); 

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); 

    layoutParams.setMargins(10, 15, 10, 10); 
    layout.setOrientation(LinearLayout.HORIZONTAL); 
    android.view.ViewGroup.LayoutParams params;  

    TextView tvTextsecond = new TextView(this); 
    tvTextsecond.setText("Heywhatrudoingtoday"); 
    tvTextsecond.setLayoutParams(layoutParams); 
    tvTextsecond.setBackgroundColor(Color.RED); 
    tvTextsecond.setTextColor(Color.WHITE); 

    TextView tvTextthird = new TextView(this); 
    tvTextthird.setText("Haiitssundaytowork"); 
    tvTextthird.setLayoutParams(layoutParams); 
    tvTextthird.setBackgroundColor(Color.BLUE); 
    tvTextthird.setTextColor(Color.WHITE); 

    TextView tvTextfourth = new TextView(this); 
    tvTextfourth.setText("Owebullshitruuselessfellow"); 
    tvTextfourth.setLayoutParams(layoutParams); 
    tvTextfourth.setBackgroundColor(Color.YELLOW); 
    tvTextfourth.setTextColor(Color.WHITE); 

    layout.addView(tvTextsecond); 
    layout.addView(tvTextthird); 
    layout.addView(tvTextfourth); 

} 

private void findViewById() { 

    layout = (LinearLayout) findViewById(R.id.flowLayout); 

} 

}

+0

不正是LinearLayout在告诉它包装其内容时做的事情吗? – 2013-04-04 10:03:01

+0

我不能理解你的问题蒂莫西。 我需要做线性布局的所有包装布局属性。 例如:如果我在3个文本视图中给出3个句子,如果没有第三个句子的空间,那么它应该在第一个位置进入下一行...... – user2109950 2013-04-04 10:26:58

+0

除了线性布局如何解决这个查询,请给我是完美的解决方案... – user2109950 2013-04-04 10:37:44

回答

0

线性布局不行为的方式。如果没有空间,它会离开你的显示区域。因此,对于您的要求,您不能在此处使用线性布局。