2013-03-18 23 views
2

我必須在Android中顯示Textviewxml Feed中獲取。textview在android中打包

讓我們看看這是我Textview

馬利卡·謝拉沃特的即將上映的電影骯髒的政治

在這裏,我已經創建的佈局動態地爲這些Textview

LinearLayout.LayoutParams textLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 50); 
textLayoutParams.gravity = Gravity.CENTER; 

TextView tv = new TextView(this); 
tv.setSingleLine(false); 
tv.setEllipsize(null); 
tv.setHorizontallyScrolling(false); 
tv.setTextColor(Color.parseColor("#a7a9ac")); 
tv.setText(Appscontent.Sub_arraylisttwo.get(j)); 
tv.setLayoutParams(textLayoutParams); 
tv.setBackgroundColor(Color.parseColor("#414042")); 

我剛纔提到的寬度50在這裏。

,使文本顯示以及小內容Textview。有些時候,我有更多的內容Textview這意味着我怎麼能顯示Textview象下面這樣:

​​

我是說文字是要顯示最高2只有在文本被擴展後的行才意味着簡單地添加...內容像上面的example.how我可以做嗎?請幫幫我 。

回答

5

與嘗試:

tv.setMaxLines(2); 
tv.setEllipsize(TextUtils.TruncateAt.END); 
+0

thanks..its爲我工作.... – user2182071 2013-03-19 04:03:03

0

嘗試設置的android:ellipsize無法比擬的每個TextView的。有關更多詳細信息,請參閱此屬性的文檔

的XML:

<TextView ... android:ellipsize="none" /> 

從代碼:

TextView textView = new TextView(context); 
... 
textView.setEllipsize(null); 
0

您可以嘗試定義爲TextView文本中strings.xml。然後,如果你從HTML設置,那麼它可以根據屏幕大小包裹:

所以你可以試試這個:

<string name="nice_html"> 
<![CDATA[Don&apos;t worry we will never share this with anyone<br/> 
By Clicking register you are indicating that you have read and agreed to the <br/> 
<u>Terms of services</u> and <u>Privacy Policy</u> 
]]></string> 

然後,在你的代碼:

TextView foo = (TextView)findViewById(R.id.foo); foo.setText(Html.fromHtml(getString(R.string.nice_html))); 
1

嘗試將設置機器人:EMS =「10」它會讓你的EditText那麼多寬,環繞文字