
當(dāng)利用textview顯示內(nèi)容時(shí),顯示內(nèi)容過多可能會折行或顯示不全,今天發(fā)現(xiàn)android api中已經(jīng)給出自動(dòng)省略的功能。
實(shí)現(xiàn)如下:
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/hello"
android:ellipsize="end" android:singleLine="true"
/>
效果:
在利用textview顯示文字時(shí),想實(shí)現(xiàn)html的效果,實(shí)現(xiàn)方法是:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textView=(TextView)findViewById(R.id.hello);
textView.setText(Html.fromHtml("Hello <b>World</b>,<font size=\"3\" color=\"red\">AnalysisXmlActivty!</font>"));
}
效果是: