2012-09-19 59 views
0

我在TextView中遇到Android LayoutParams問題。我想在一個尺寸爲200 dip x 200 dip的文本框中顯示一個文本。但沒有任何表現。這是代碼:Android LayoutParams什麼都不做

tr = new TableRow(this); 
TextView phone = new TextView(this); 
phone.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE); 
phone.setLines(20); 
phone.setText(Html.fromHtml("<b>Beschreibung</b><br /><br />")); 
phone.append(poi.getDescription()); 
tr.addView(phone,new ViewGroup.LayoutParams(calculatePxs(200),calculatePxs(200))); 
     tr.setPadding(10, 15, 10, 15); 

v = new View(this); 
v.setBackgroundColor(Color.rgb(51, 51, 51)); 

table.addView(tr,new TableLayout.LayoutParams(
       LayoutParams.WRAP_CONTENT, 
       LayoutParams.WRAP_CONTENT)); 

table.addView(v,new TableLayout.LayoutParams(
       LayoutParams.WRAP_CONTENT, 
       1)); 

回答

0

而不是

new ViewGroup.LayoutParams(calculatePxs(200),calculatePxs(200))); 
    tr.setPadding(10, 15, 10, 15); 

使用TableRow.LayoutParams

像:

new TableRow.LayoutParams(calculatePxs(200),calculatePxs(200))); 
tr.setPadding(10, 15, 10, 15); 
+0

歐凱工程。但是TextView在文本到達邊界時確實會換行。你知道爲什麼嗎? – Bene

+0

試試這個職位:http://stackoverflow.com/questions/4831529/android-single-line-textview-without-the-dots –

+0

已經嘗試過,沒有成功... – Bene