2013-04-04 58 views
0

我在3個文本視圖中以水平方向在JAVA文件中給出3個句子,但只有2個文本視圖只有2個句子是comin,但第三句由於移動的分辨率而消失。我的查詢是如何從第二行的開始位置開始,而不是最後一行,從第三行開始。JAVA中的Android流佈局

public class MainActivity extends Activity { 

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); 

    TextView tvTextsecond = new TextView(this); 
    tvTextsecond.setText("Heywhatrudoingtoday"); 
    tvTextsecond.setLayoutParams(layoutParams); 
    tvTextsecond.setBackgroundColor(Color.RED); 
    tvTextsecond.setTextColor(Color.WHITE); 
    //tvTextsecond.setSingleLine(true); 
    layout.addView(tvTextsecond); 

    TextView tvTextthird = new TextView(this); 
    tvTextthird.setText("Haiitssundaytowork"); 
    tvTextthird.setLayoutParams(layoutParams); 
    tvTextthird.setBackgroundColor(Color.BLUE); 
    tvTextthird.setTextColor(Color.WHITE); 
    //tvTextthird.setSingleLine(true); 
    layout.addView(tvTextthird); 

    TextView tvTextfourth = new TextView(this); 
    tvTextfourth.setText("Owebullshitruuselessfellow"); 
    tvTextfourth.setLayoutParams(layoutParams); 
    tvTextfourth.setBackgroundColor(Color.YELLOW); 
    tvTextfourth.setTextColor(Color.WHITE); 
    //tvTextfourth.setSingleLine(true); 
    layout.addView(tvTextfourth); 

} 

private void findViewById() { 
    layout = (LinearLayout) findViewById(R.id.flowLayout); 

} 

} 

回答

0

看不到第三TextView的原因是,你的佈局具有水平方向和而前兩個TextView小號適合屏幕尺寸,第三個是越來越外推。

要解決這個問題,你可以做以下幾個步驟:

1.改變你的佈局方向在XML或Java文件,這樣垂直TextView會出現一個接一個垂直後。

2.如果你想保持一個以上的TextView連續,那麼你還是應該設置您的主要佈局方向爲垂直,但對於TextView每一行的創建與使用代碼水平方向新佈局並將TextView添加到此佈局。

LinearLayout tvRow = new LinearLayout(); 
tvRow.addView(firstTextView); 
tvRow.addView(secondTextView); 

最後這個佈局添加到您的主要佈局:

mailLayout.addView(tvRow);