2013-04-04 62 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

線性佈局不行爲的方式。如果沒有空間,它會離開你的顯示區域。因此,對於您的要求,您不能在此處使用線性佈局。