txtvw.setText("The Indian economy is the world's eleventh-largest by nominal GDP and third-largest by purchasing power parity (PPP). " +
" Following market-based economic reforms in 1991, India became one of the fastest-growing major economies; " +
" it is considered a newly industrialised country. However, it continues to face the challenges of poverty, illiteracy, corruption, malnutrition, and inadequate public healthcare. " +
" A nuclear weapons state and a regional power, it has the third-largest standing army in the world and ranks ninth in military expenditure among nations." +
" India is a federal constitutional republic governed under a parliamentary system consisting of 28 states and 7 union territories. " +
" India is a pluralistic, multilingual, and multiethnic society. " +
" It is also home to a diversity of wildlife in a variety of protected habitats.");
ViewTreeObserver vto = txtvw.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
ViewTreeObserver obs = txtvw.getViewTreeObserver();
obs.removeGlobalOnLayoutListener(this);
if(txtvw.getLineCount() > 1){
int lineEndIndex = txtvw.getLayout().getLineEnd(1);
String text = txtvw.getText().subSequence(0, lineEndIndex-3)+"...";
txtvw.setText(text);
}
}
});
向我們展示了您用於textview的XML。我有一種感覺,你使用'android:layout_width =「wrap_content」' – Blundell 2012-03-26 11:06:24
你可以嘗試使用android:ellipsize =「marquee」。 – YuviDroid 2012-03-26 11:07:29
with'android:layout_width =「wrap_content」'它仍然不應該ellipsize文本...也許任何父容器有一個寬度的限制.. – pleerock 2012-03-26 11:11:03